@glueforms/react 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +110 -2
- package/THIRD-PARTY-NOTICES.txt +43 -0
- package/dist/form.css +495 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +650 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +256 -0
- package/package.json +63 -4
- package/source/index.d.ts +17 -0
- package/source/index.jsx +557 -0
- package/source/shared/dates.js +225 -0
- package/source/shared/form.css +495 -0
- package/source/shared/native.js +17 -0
- package/source/shared/ownership.js +50 -0
- package/source/shared/styles.css +256 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inBounds } from "./dates.js";
|
|
2
|
+
// The browser owns date step parsing and rounding. A detached, writable probe
|
|
3
|
+
// preserves those rules without changing the successful form control.
|
|
4
|
+
export function nativeSelectable(probe, value, range, step, defaultValue) {
|
|
5
|
+
if (!inBounds(value, range)) return false;
|
|
6
|
+
probe.type = "date";
|
|
7
|
+
for (const [name, candidate] of Object.entries({
|
|
8
|
+
min: range.min || "",
|
|
9
|
+
step: step ?? "",
|
|
10
|
+
value: defaultValue ?? "",
|
|
11
|
+
})) {
|
|
12
|
+
const text = String(candidate);
|
|
13
|
+
if (probe.getAttribute(name) !== text) probe.setAttribute(name, text);
|
|
14
|
+
}
|
|
15
|
+
probe.value = value;
|
|
16
|
+
return !probe.validity.stepMismatch;
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const VERSION = "0.2.0";
|
|
2
|
+
const registryKey = Symbol.for("glueforms.public.date-fields.ownership");
|
|
3
|
+
export function acquire(root, kind, create) {
|
|
4
|
+
const document = root?.nodeType === 9 ? root : root?.ownerDocument;
|
|
5
|
+
const view = document?.defaultView;
|
|
6
|
+
if (!view || !(root instanceof view.Document || root instanceof view.Element))
|
|
7
|
+
throw new TypeError("GlueForms init requires a Document or Element root.");
|
|
8
|
+
let registry = document[registryKey];
|
|
9
|
+
if (
|
|
10
|
+
registry &&
|
|
11
|
+
(registry.version !== VERSION || !(registry.owners instanceof Map))
|
|
12
|
+
)
|
|
13
|
+
throw new Error(
|
|
14
|
+
"An incompatible GlueForms version already owns this document.",
|
|
15
|
+
);
|
|
16
|
+
if (registry)
|
|
17
|
+
for (const [other, record] of registry.owners) {
|
|
18
|
+
if (root === other && record.kind === kind && kind === "core")
|
|
19
|
+
return record.handle;
|
|
20
|
+
if (
|
|
21
|
+
root === other ||
|
|
22
|
+
view.Node.prototype.contains.call(root, other) ||
|
|
23
|
+
view.Node.prototype.contains.call(other, root)
|
|
24
|
+
)
|
|
25
|
+
throw new Error(
|
|
26
|
+
"GlueForms roots overlap. Dispose the existing owner before initializing this root.",
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
registry = { version: VERSION, owners: new Map() };
|
|
31
|
+
Object.defineProperty(document, registryKey, {
|
|
32
|
+
value: registry,
|
|
33
|
+
configurable: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const release = () => {
|
|
37
|
+
registry.owners.delete(root);
|
|
38
|
+
if (!registry.owners.size && document[registryKey] === registry)
|
|
39
|
+
delete document[registryKey];
|
|
40
|
+
};
|
|
41
|
+
const record = { kind, handle: null };
|
|
42
|
+
registry.owners.set(root, record);
|
|
43
|
+
try {
|
|
44
|
+
record.handle = create(document, view, release);
|
|
45
|
+
return record.handle;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
release();
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
.gf-calendar {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
min-width: 0;
|
|
4
|
+
width: 100%;
|
|
5
|
+
margin-top: 8px;
|
|
6
|
+
padding: 17px 19px 13px;
|
|
7
|
+
border: 1px solid var(--gf-calendar-border, #dfe3ed);
|
|
8
|
+
border-radius: var(--gf-calendar-radius, 11px);
|
|
9
|
+
background: var(--gf-calendar-background, #fff);
|
|
10
|
+
color: var(--gf-calendar-text, #343a4b);
|
|
11
|
+
font: inherit;
|
|
12
|
+
font-weight: 400;
|
|
13
|
+
line-height: 1.5;
|
|
14
|
+
}
|
|
15
|
+
.gf-calendar * {
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
}
|
|
18
|
+
.gf-calendar-header {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: space-between;
|
|
22
|
+
gap: 8px;
|
|
23
|
+
margin-bottom: 16px;
|
|
24
|
+
}
|
|
25
|
+
.gf-calendar-month {
|
|
26
|
+
font-size: 14px;
|
|
27
|
+
font-weight: 600;
|
|
28
|
+
text-align: center;
|
|
29
|
+
text-transform: capitalize;
|
|
30
|
+
letter-spacing: -0.025em;
|
|
31
|
+
}
|
|
32
|
+
.gf-calendar-nav {
|
|
33
|
+
display: flex;
|
|
34
|
+
gap: 3px;
|
|
35
|
+
flex-shrink: 0;
|
|
36
|
+
}
|
|
37
|
+
.gf-calendar .gf-calendar-nav-button {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
width: 29px;
|
|
42
|
+
height: 29px;
|
|
43
|
+
min-height: 0;
|
|
44
|
+
padding: 0;
|
|
45
|
+
border: 1px solid #e3e5ec;
|
|
46
|
+
border-radius: 6px;
|
|
47
|
+
background: var(--gf-calendar-background, #fff);
|
|
48
|
+
color: #5d6478;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
}
|
|
51
|
+
.gf-calendar-nav-button svg {
|
|
52
|
+
width: 15px;
|
|
53
|
+
height: 15px;
|
|
54
|
+
}
|
|
55
|
+
.gf-calendar .gf-calendar-nav-button:hover:not(:disabled) {
|
|
56
|
+
background: #f1f4ff;
|
|
57
|
+
color: var(--gf-calendar-accent, #2541e8);
|
|
58
|
+
border-color: #bac8ff;
|
|
59
|
+
}
|
|
60
|
+
.gf-calendar-grid,
|
|
61
|
+
.gf-calendar-days {
|
|
62
|
+
display: grid;
|
|
63
|
+
gap: 5px;
|
|
64
|
+
}
|
|
65
|
+
.gf-calendar-row {
|
|
66
|
+
display: grid;
|
|
67
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
68
|
+
gap: 5px;
|
|
69
|
+
}
|
|
70
|
+
.gf-calendar-weekday {
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
text-overflow: clip;
|
|
73
|
+
text-align: center;
|
|
74
|
+
font-size: 11px;
|
|
75
|
+
font-weight: 500;
|
|
76
|
+
line-height: 26px;
|
|
77
|
+
color: var(--gf-calendar-muted, #686e7e);
|
|
78
|
+
}
|
|
79
|
+
.gf-calendar-cell {
|
|
80
|
+
display: flex;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
}
|
|
84
|
+
.gf-calendar .gf-calendar-day {
|
|
85
|
+
position: relative;
|
|
86
|
+
width: 100%;
|
|
87
|
+
max-width: 42px;
|
|
88
|
+
min-height: 38px;
|
|
89
|
+
padding: 0;
|
|
90
|
+
border: 1px solid transparent;
|
|
91
|
+
border-radius: 7px;
|
|
92
|
+
background: var(--gf-calendar-background, #fff);
|
|
93
|
+
color: var(--gf-calendar-text, #343a4b);
|
|
94
|
+
font: inherit;
|
|
95
|
+
font-size: 13px;
|
|
96
|
+
font-weight: 450;
|
|
97
|
+
font-variant-numeric: tabular-nums;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
}
|
|
100
|
+
.gf-calendar .gf-calendar-day:hover:not(:disabled) {
|
|
101
|
+
background: #edf2ff;
|
|
102
|
+
border-color: #cdd8ff;
|
|
103
|
+
color: var(--gf-calendar-accent, #2541e8);
|
|
104
|
+
}
|
|
105
|
+
.gf-calendar .gf-calendar-day[data-outside="true"] {
|
|
106
|
+
color: #81899b;
|
|
107
|
+
}
|
|
108
|
+
.gf-calendar
|
|
109
|
+
.gf-calendar-day[aria-current="date"]:not([aria-pressed="true"]):after {
|
|
110
|
+
content: "";
|
|
111
|
+
position: absolute;
|
|
112
|
+
bottom: 3px;
|
|
113
|
+
left: calc(50% - 1.5px);
|
|
114
|
+
height: 3px;
|
|
115
|
+
width: 3px;
|
|
116
|
+
border-radius: 50%;
|
|
117
|
+
background: var(--gf-calendar-accent, #2541e8);
|
|
118
|
+
}
|
|
119
|
+
.gf-calendar .gf-calendar-day[aria-pressed="true"] {
|
|
120
|
+
background: var(--gf-calendar-accent, #2541e8);
|
|
121
|
+
border-color: var(--gf-calendar-accent, #2541e8);
|
|
122
|
+
color: var(--gf-calendar-accent-text, #fff);
|
|
123
|
+
font-weight: 600;
|
|
124
|
+
box-shadow: 0 2px 5px #2541e822;
|
|
125
|
+
}
|
|
126
|
+
.gf-calendar .gf-calendar-day:disabled,
|
|
127
|
+
.gf-calendar .gf-calendar-nav-button:disabled {
|
|
128
|
+
opacity: 1;
|
|
129
|
+
color: #b1b7c5;
|
|
130
|
+
background: #f8f9fb;
|
|
131
|
+
cursor: default;
|
|
132
|
+
}
|
|
133
|
+
.gf-calendar .gf-calendar-day:disabled {
|
|
134
|
+
background: transparent;
|
|
135
|
+
}
|
|
136
|
+
.gf-calendar .gf-calendar-day[aria-pressed="true"]:disabled {
|
|
137
|
+
background: #e8ebf3;
|
|
138
|
+
color: #697086;
|
|
139
|
+
border-color: #e8ebf3;
|
|
140
|
+
box-shadow: none;
|
|
141
|
+
}
|
|
142
|
+
.gf-calendar-footer {
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: center;
|
|
145
|
+
justify-content: space-between;
|
|
146
|
+
gap: 10px;
|
|
147
|
+
border-top: 1px solid #edf0f5;
|
|
148
|
+
padding-top: 12px;
|
|
149
|
+
margin-top: 12px;
|
|
150
|
+
}
|
|
151
|
+
.gf-calendar-policy {
|
|
152
|
+
color: var(--gf-calendar-muted, #686e7e);
|
|
153
|
+
font-size: 11px;
|
|
154
|
+
}
|
|
155
|
+
.gf-calendar .gf-calendar-clear {
|
|
156
|
+
min-height: 0;
|
|
157
|
+
padding: 3px;
|
|
158
|
+
border: 0;
|
|
159
|
+
border-radius: 4px;
|
|
160
|
+
background: none;
|
|
161
|
+
color: var(--gf-calendar-accent, #2541e8);
|
|
162
|
+
font: inherit;
|
|
163
|
+
font-size: 12px;
|
|
164
|
+
cursor: pointer;
|
|
165
|
+
}
|
|
166
|
+
.gf-calendar .gf-calendar-clear:disabled {
|
|
167
|
+
color: #9298a7;
|
|
168
|
+
cursor: default;
|
|
169
|
+
}
|
|
170
|
+
.gf-calendar-selection {
|
|
171
|
+
min-height: 35px;
|
|
172
|
+
margin: 11px 0 0;
|
|
173
|
+
padding: 9px 11px;
|
|
174
|
+
border-radius: 6px;
|
|
175
|
+
background: #f5f7fc;
|
|
176
|
+
color: #606a80;
|
|
177
|
+
font-size: 12px;
|
|
178
|
+
overflow-wrap: anywhere;
|
|
179
|
+
}
|
|
180
|
+
.gf-calendar-selection[data-selected="true"] {
|
|
181
|
+
background: #eef3ff;
|
|
182
|
+
color: var(--gf-calendar-accent, #2541e8);
|
|
183
|
+
}
|
|
184
|
+
.gf-calendar button:focus-visible {
|
|
185
|
+
outline: 2px solid var(--gf-calendar-accent, #2541e8);
|
|
186
|
+
outline-offset: 3px;
|
|
187
|
+
z-index: 1;
|
|
188
|
+
}
|
|
189
|
+
.gf-calendar-sr-only {
|
|
190
|
+
position: absolute;
|
|
191
|
+
width: 1px;
|
|
192
|
+
height: 1px;
|
|
193
|
+
padding: 0;
|
|
194
|
+
margin: -1px;
|
|
195
|
+
overflow: hidden;
|
|
196
|
+
clip: rect(0, 0, 0, 0);
|
|
197
|
+
white-space: nowrap;
|
|
198
|
+
border: 0;
|
|
199
|
+
}
|
|
200
|
+
@media (max-width: 420px) {
|
|
201
|
+
.gf-calendar {
|
|
202
|
+
padding: 14px 10px 12px;
|
|
203
|
+
}
|
|
204
|
+
.gf-calendar-row {
|
|
205
|
+
gap: 3px;
|
|
206
|
+
}
|
|
207
|
+
.gf-calendar-month {
|
|
208
|
+
font-size: 12px;
|
|
209
|
+
}
|
|
210
|
+
.gf-calendar-nav {
|
|
211
|
+
gap: 2px;
|
|
212
|
+
}
|
|
213
|
+
.gf-calendar .gf-calendar-nav-button {
|
|
214
|
+
width: 25px;
|
|
215
|
+
height: 28px;
|
|
216
|
+
}
|
|
217
|
+
.gf-calendar .gf-calendar-day {
|
|
218
|
+
min-height: 35px;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* Keep the form primary color on the selected day, not every calendar button. */
|
|
223
|
+
.gf-primary-color .gf-calendar .gf-calendar-day:not([aria-pressed="true"]),
|
|
224
|
+
.gf-primary-color .gf-calendar .gf-calendar-nav-button,
|
|
225
|
+
.gf-primary-color .gf-calendar .gf-calendar-clear {
|
|
226
|
+
background-color: #ffffff !important;
|
|
227
|
+
border-color: #e3e5ec !important;
|
|
228
|
+
color: var(--gf-calendar-text, #343a4b) !important;
|
|
229
|
+
}
|
|
230
|
+
.gf-primary-color
|
|
231
|
+
.gf-calendar
|
|
232
|
+
.gf-calendar-day:not([aria-pressed="true"]):hover:not(:disabled),
|
|
233
|
+
.gf-primary-color .gf-calendar .gf-calendar-nav-button:hover:not(:disabled),
|
|
234
|
+
.gf-primary-color .gf-calendar .gf-calendar-clear:hover:not(:disabled) {
|
|
235
|
+
background-color: #f1f3f6 !important;
|
|
236
|
+
border-color: #697086 !important;
|
|
237
|
+
}
|
|
238
|
+
.gf-primary-color .gf-calendar .gf-calendar-day[aria-pressed="true"] {
|
|
239
|
+
box-shadow: none;
|
|
240
|
+
}
|
|
241
|
+
.gf-primary-color .gf-calendar .gf-calendar-day:disabled,
|
|
242
|
+
.gf-primary-color .gf-calendar .gf-calendar-nav-button:disabled,
|
|
243
|
+
.gf-primary-color .gf-calendar .gf-calendar-clear:disabled {
|
|
244
|
+
background-color: #f8f9fb !important;
|
|
245
|
+
border-color: #e3e5ec !important;
|
|
246
|
+
color: #9298a7 !important;
|
|
247
|
+
}
|
|
248
|
+
.gf-primary-color
|
|
249
|
+
.gf-calendar
|
|
250
|
+
.gf-calendar-day[aria-current="date"]:not([aria-pressed="true"]):after {
|
|
251
|
+
background: currentColor;
|
|
252
|
+
}
|
|
253
|
+
.gf-primary-color .gf-calendar .gf-calendar-selection[data-selected="true"] {
|
|
254
|
+
background: #f1f3f6;
|
|
255
|
+
color: var(--gf-calendar-text, #343a4b);
|
|
256
|
+
}
|