-
Notifications
You must be signed in to change notification settings - Fork 393
/
multiselect.ts
131 lines (104 loc) · 3.43 KB
/
multiselect.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import css from 'style-convert/macro'
import colors from 'tailwindcss/colors'
import { PluginApi, ThemeFn } from 'tailwindcss/plugin'
export const theme = {
rwMultiselect: (theme: ThemeFn) => {
const input = theme('rwInput')
const gutter = 0.115
return {
tagPaddingInlineStart: theme('padding[1.5]'),
tagPaddingInlineEnd: theme('padding[1.5]'),
tagColor: null,
tagBorderColor: theme('colors.gray.300', colors.gray[300]),
tagBackgroundColor: theme('colors.gray.300', colors.gray[300]),
tagGutter: `calc(${input.height} * ${gutter} - ${input.borderWidth})`,
tagHeight: `calc(${input.height} * ${1 - gutter * 2})`,
tagBorderRadius: theme('borderRadius.DEFAULT'),
tagBtnPaddingY: 0,
tagBtnPaddingX: theme('padding[1.5]'),
tagBtnBackgroundColor: null,
tagBtnBorderColor: null,
tagBtnColor: null,
tagBtnHoverBackgroundColor: null,
tagBtnHoverBorderColor: null,
tagBtnHoverColor: null,
tagBtnActiveBackgroundColor: null,
tagBtnActiveBorderColor: null,
tagBtnActiveColor: null,
}
},
}
export const plugin = ({ theme, addComponents }: PluginApi) => {
const input = theme('rwInput')
const ms = theme('rwMultiselect')
addComponents(css`
.rw-multiselect {
}
.rw-multiselect-input {
@apply rw-btn-input-reset rw-input-base;
height: calc(${input.height} - ${input.borderWidth} * 2);
padding: 0 ${input.paddingX};
max-width: 100%; // breaks to a new line but doesn't stop growing
&:disabled,
&:read-only {
// use parent style
cursor: inherit;
}
}
.rw-multiselect-taglist {
@apply flex flex-wrap items-start w-full outline-none cursor-text;
.rw-state-disabled & {
cursor: unset;
}
}
.rw-multiselect-tag {
@apply inline-flex items-center overflow-hidden max-w-full;
// reset the text selection cursor on the parent
@apply cursor-default;
color: ${ms.tagColor};
margin-left: ${ms.tagGutter};
margin-top: ${ms.tagGutter};
min-height: ${ms.tagHeight};
border-radius: ${ms.tagBorderRadius};
background-color: ${ms.tagBackgroundColor};
border: ${ms.tagBorderColor ? `1px solid ${ms.tagBorderColor}` : null};
[dir='rtl'] & {
margin-left: 0;
margin-right: ${ms.tagGutter};
padding: 0 ${ms.tagPaddingInlineStart} 0 ${ms.tagPaddingInlineEnd};
}
&.rw-state-focus {
@apply rw-focus-ring;
zindex: 1;
}
&.rw-state-disabled,
fieldset[disabled] & {
opacity: 0.65;
}
}
.rw-multiselect-tag-label {
padding: 0 ${ms.tagPaddingInlineEnd} 0 ${ms.tagPaddingInlineStart};
}
.rw-multiselect-tag-btn {
@apply rw-btn-input-reset cursor-pointer self-stretch;
padding: ${ms.tagBtnPaddingY} ${ms.tagBtnPaddingX};
color: ${ms.tagBtnColor};
border-color: ${ms.tagBtnBorderColor};
background-color: ${ms.tagBtnBackgroundColor};
&:hover {
color: ${ms.tagBtnHoverColor};
border-color: ${ms.tagBtnHoverBorderColor};
background-color: ${ms.tagBtnHoverBackgroundColor};
}
&:active {
color: ${ms.tagBtnActiveColor};
border-color: ${ms.tagBtnActiveBorderColor};
background-color: ${ms.tagBtnActiveBackgroundColor};
}
&:disabled {
cursor: inherit;
}
@apply focus:outline-none;
}
`)
}