-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
149 lines (133 loc) · 4.56 KB
/
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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import plugin from "tailwindcss/plugin";
const WidgetAttributes = {
autocomplete: ["none", "inline", "list", "both"],
checked: ["false", "true", "mixed"],
// disabled: ["true", "false"], duplicate
// errormessage: ["id"], duplicate
expanded: ["true", "false"],
// haspopup: ["false", "true", "menu", "listbox", "tree", "grid", "dialog"], duplicate
// hidden: ["false", "true"], duplicate
// invalid: ["grammar", "false", "spelling", "true"], duplicate
// label: ["<string>"], duplicate
level: ["<integer>"],
modal: ["false", "true"],
multiline: ["false", "true"],
multiselectable: ["false", "true"],
orientation: ["horizontal", "vertical"],
placeholder: ["<string>"],
pressed: ["false", "mixed", "true"],
readonly: ["true", "false"],
required: ["true", "false"],
selected: ["true", "false"],
sort: ["ascending", "descending", "none", "other"],
valuemax: ["<number>"],
valuemin: ["<number>"],
valuenow: ["<number>"],
valuetext: ["<string>"],
};
/* ============================================================= *
* Live region attributes *
* ============================================================= */
const LiveRegionAttributes = {
busy: ["false", "true"],
live: ["assertive", "off", "polite"],
relevant: ["additions", "all", "removals", "text" /* "additions text" */],
atomic: ["false", "true"],
};
/* ============================================================= *
* Drag-and-Drop attributes *
* ============================================================= */
const DragAndDropAttributes = {
dropeffect: ["copy", "execute", "link", "move", "none", "popup"],
grabbed: ["true", "false"],
};
/* ============================================================= *
* Relationship attributes *
* ============================================================= */
const RelationshipAttributes = {
activedescendant: ["id"],
colcount: ["<integer>"],
colindex: ["<integer>"],
colspan: ["<integer>"],
controls: ["id list"],
describedby: ["ID reference list"],
description: ["<string>"],
details: ["ID reference list"],
// errormessage: ["id reference"], duplicate
flowto: ["id" /* "id list" */],
labelledby: ["ID reference list"],
owns: ["id list"],
posinset: ["<integer>"],
rowcount: ["<integer>"],
rowindex: ["<integer>"],
rowspan: ["<integer>"],
setsize: ["<integer>"],
};
/* ============================================================= *
* Global ARIA attributes *
* ============================================================= */
const GlobalAriaAttributes = {
atomic: ["false", "true"],
busy: ["false", "true"],
controls: ["id"],
current: ["page", "step", "location", "date", "time", "true", "false"],
describedby: ["id"],
// description: [],
details: ["id"],
disabled: ["true", "false"],
dropeffect: ["copy", "execute", "link", "move", "none", "popup"],
errormessage: ["id"],
flowto: ["id"],
grabbed: ["true", "false"],
haspopup: ["false", "true", "menu", "listbox", "tree", "grid", "dialog"],
hidden: ["false", "true"],
invalid: ["grammar", "false", "spelling", "true"],
// keyshortcuts: [],
label: ["<string>"],
labelledby: ["id"],
live: ["assertive", "off", "polite"],
owns: ["id"],
relevant: ["additions", "all", "removals", "text", "additions text"],
// roledescription: [],
};
const generateNameWithValue = (key: string, value: string) => {
// => aria-[key]
if (value === "true") {
return `aria-${key}`;
}
// => aria-![key]
if (value === "false") {
return `aria-!${key}`;
}
// => aria-[key]-[value]
return `aria-${key}-${value}`;
};
export = plugin(({ addVariant }) => {
const Attributes = [
WidgetAttributes,
LiveRegionAttributes,
DragAndDropAttributes,
RelationshipAttributes,
GlobalAriaAttributes,
];
for (const attributes of Attributes) {
for (const [key, variants] of Object.entries(attributes)) {
// only one variants => aria-[key]
if (variants.length === 1) {
const name = `aria-${key}`;
// => aria
addVariant(name, `&[aria-${key}]`);
// => group-aria
addVariant(`group-${name}`, `:merge(.group)[aria-${key}] &`);
continue;
}
for (const value of variants) {
const name = generateNameWithValue(key, value);
// => aria
addVariant(name, `&[aria-${key}="${value}"]`);
// => group-aria
addVariant(`group-${name}`, `:merge(.group)[aria-${key}="${value}"] &`);
}
}
}
});