-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
33 lines (29 loc) · 892 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { Context, CSSRules, ThemeSection, Directive } from 'twind'
import { directive } from 'twind'
declare module 'twind' {
interface Theme {
lineClamp?: ThemeSection<string | number>
}
}
export interface LineClamp {
(lines: 'none' | number | string): Directive<CSSRules>
(parts: string[], context: Context): CSSRules
}
const lineClamp$ = (lines: string, { theme }: Context): CSSRules =>
lines === 'none'
? {
WebkitLineClamp: 'unset',
}
: {
overflow: 'hidden',
display: '-webkit-box',
WebkitBoxOrient: 'vertical',
WebkitLineClamp: `${theme('lineClamp', lines, lines)}`,
}
export const lineClamp = ((
lines: number | 'none' | string[],
context: Context,
): Directive<CSSRules> | CSSRules =>
Array.isArray(lines)
? lineClamp$(lines[0], context)
: directive(lineClamp$, `${lines}`)) as LineClamp