Skip to content

Instantly share code, notes, and snippets.

View tsmd's full-sized avatar

Shimada Takayuki tsmd

View GitHub Profile
@tsmd
tsmd / web-storage.ts
Created February 1, 2020 11:21
localStorage, sessionStorage のごく薄いラッパー。Cookie 無効環境でストレージにアクセスしたときに発生する例外を捕捉しスクリプトが止まらないようにする。
/**
* @fileOverview
* localStorage, sessionStorage のごく薄いラッパー。
* Cookie 無効環境でストレージにアクセスしたときに発生する例外を捕捉しスクリプトが止まらないようにする。
*/
type storageType = 'localStorage' | 'sessionStorage'
class WebStorage {
constructor(private storageType: storageType) {}
function rollFocus(backFlag) {
let focusIndex
const currentIndex = this.tabbableElements.indexOf(document.activeElement)
if (currentIndex < 0) {
focusIndex = 0
} else {
const tabbableLength = this.tabbableElements.length
const direction = backFlag ? -1 : 1
focusIndex = (currentIndex + direction + tabbableLength) % tabbableLength
}
/**
* 画像の回転を取得する
* @returns {number} 回転を表す数字。正しく表示するために数字に応じて以下の処理をする:
* 1: 何もしない
* 2: 左右反転
* 3: 180度回転
* 4: 180度回転し、左右反転
* 5: 時計回りに90度回転し、左右反転
* 6: 時計回りに90度回転
* 7: 時計回りに270度回転し、左右反転
/**
* 引数を起点に兄弟要素、親の兄弟要素、さらに親の兄弟要素、…を取得する
* @param {Element} baseElement
* @return {[Element]} 対象となるHTML要素
*/
export function collectAllSiblings(baseElement) {
const targets = []
let current = baseElement
while (current && current !== document.body) {
const siblings = Array.from(current.parentNode.children)
@tsmd
tsmd / _textarea.scss
Last active May 30, 2019 15:10
Cool textarea
@charset "UTF-8";
.Textarea {
@at-root {
& {
position: relative;
color: inherit;
font-size: rem(16px);
line-height: 1.8;
}
@tsmd
tsmd / _text-input.scss
Created May 29, 2019 00:38
Cool text input
@charset "UTF-8";
.TextInput {
@at-root {
& {
width: 100%;
height: rem(40px);
padding: 0 rem(14px);
border: 0;
color: inherit;
@tsmd
tsmd / _radio.scss
Created May 29, 2019 00:32
Cool radio button
@charset "UTF-8";
.Radio {
@at-root {
& {
position: relative;
z-index: 0;
display: inline-flex;
justify-content: flex-start;
align-items: baseline;
@tsmd
tsmd / _checkbox.scss
Created May 29, 2019 00:30
Cool checkbox
@charset "UTF-8";
.Checkbox {
@at-root {
@function checked-icon($color: #fff) {
$color: '' + $color;
$color: '%23' + str-slice($color, 2);
@return 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M9%2016.17L4.83%2012l-1.42%201.41L9%2019%2021%207l-1.41-1.41z%22%20fill%3D%22#{$color}%22%2F%3E%3C%2Fsvg%3E';
}
let scrollbarWidth;
export default function measureScrollBarWidth(opts = {}) {
const { force = false } = opts;
if (force || typeof scrollbarWidth === "undefined") {
const div = document.createElement("div");
div.style.position = "absolute";
div.style.overflowY = "scroll";
div.style.width = div.style.height = "100px";
@tsmd
tsmd / smooth-scroll-2.css
Last active October 27, 2018 17:03
FLIP implementation of smooth scrolling supporting some fixed elements
.smooth-scroll {
transition: transform 0.5s ease-out !important;
}
.smooth-scroll-fixed {
display: none !important;
}