This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set `aria-live` manually here as we cannot use Swiper's navigation since we use custom arrows. | |
*/ | |
function setAriaLive(el: HTMLDivElement | null, value: string) { | |
if (!el) return; | |
el.innerHTML = ''; | |
setTimeout(() => { | |
el.innerHTML = `<div aria-live="polite" aria-atomic="true" className="visually-hidden">${value}</div>`; | |
}, 100); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define either undefined or null | |
type Maybe<T> = T | undefined | null; | |
type User = { | |
name: string | |
email: string | |
phone: Maybe<string> | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When all keys are optional | |
type User = Partial<{ | |
name: string | |
email: string | |
phone: string | |
}> | |
/** | |
type User = { | |
name?: string | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When one key is optional | |
type User = { | |
name: string | |
email: string | |
phone?: string | |
} | |
/** | |
type User = { | |
name: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sizes = [ | |
{ variant: 'sm', value: 8 }, | |
{ variant: 'md', value: 16 }, | |
{ variant: 'lg', value: 24 }, | |
] as const | |
type SizeKey = keyof typeof sizes[number] // "variant" | "value" | |
type SizeVariant = typeof sizes[number]['variant'] // "sm" | "md" | "lg" | |
type SizeValue = typeof sizes[number]['value'] // 8 | 16 | 24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const colors = { | |
bg: '#e5e5e5', | |
navy: '#002b45', | |
orange: '#fb5a3b', | |
darkOrange: '#cf4d34', | |
} as const | |
type ColorValue = typeof colors[keyof typeof colors] // "#e5e5e5" | "#002b45" | "#fb5a3b" | "#cf4d34" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const colors = { | |
bg: '#e5e5e5', | |
navy: '#002b45', | |
orange: '#fb5a3b', | |
darkOrange: '#cf4d34', | |
} as const | |
type ColorKey = keyof typeof colors // "navy" | "orange" | "bg" | "darkOrange" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
A hook to manage boolean | |
@example | |
function Example() { | |
const [flag, setFlag] = useBoolean() | |
return ( | |
<> | |
<p>Boolean state: {flag}</p> | |
<button onClick={setFlag.on}>On</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.mask-gradient-bottom { | |
mask-image: linear-gradient(to bottom, black 2%, transparent 98%); | |
} | |
.mask-gradient-top { | |
mask-image: linear-gradient(to top, black 2%, transparent 98%); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.line-clamp { | |
-webkit-box-orient: vertical; | |
-webkit-line-clamp: 2; /* max line length */ | |
display: -webkit-box; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} |
NewerOlder