@canonical/react-ds-global-form 0.36.0 → 0.38.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/README.md +40 -0
- package/dist/esm/density.css +320 -302
- package/dist/esm/docs/examples/density-examples.css +19 -14
- package/dist/esm/index.css +361 -335
- package/dist/esm/lib/_work_in_progress/DensityTestbed/baseline-system.css +71 -64
- package/dist/esm/lib/_work_in_progress/DensityTestbed/density.testbed.css +127 -123
- package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +73 -54
- package/dist/esm/lib/common/Wrapper/styles.css +35 -31
- package/dist/esm/lib/component/ChoicesField/common/Option/Option.js +4 -1
- package/dist/esm/lib/component/ChoicesField/common/Option/Option.js.map +1 -1
- package/dist/esm/lib/component/ChoicesField/styles.css +195 -163
- package/dist/esm/lib/component/RangeField/common/RangeControl/styles.css +39 -35
- package/dist/esm/lib/component/RichChoicesField/styles.css +93 -89
- package/dist/esm/lib/index.js +2 -0
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/CheckboxInput/styles.css +115 -111
- package/dist/esm/lib/subcomponent/ColorInput/styles.css +177 -173
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/styles.css +33 -29
- package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/styles.css +21 -17
- package/dist/esm/lib/subcomponent/ComboboxInput/styles.css +59 -55
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/DateInput/styles.css +23 -19
- package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -20
- package/dist/esm/lib/subcomponent/Field/Description/styles.css +9 -5
- package/dist/esm/lib/subcomponent/Field/Error/styles.css +9 -5
- package/dist/esm/lib/subcomponent/Field/Label/Label.js +2 -2
- package/dist/esm/lib/subcomponent/Field/Label/Label.js.map +1 -1
- package/dist/esm/lib/subcomponent/Field/Label/styles.css +25 -21
- package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +125 -119
- package/dist/esm/lib/subcomponent/NumberInput/styles.css +32 -28
- package/dist/esm/lib/subcomponent/PasswordInput/styles.css +58 -54
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/PhoneInput/styles.css +53 -49
- package/dist/esm/lib/subcomponent/RadioInput/styles.css +70 -66
- package/dist/esm/lib/subcomponent/RangeInput/styles.css +74 -70
- package/dist/esm/lib/subcomponent/RatingInput/styles.css +132 -128
- package/dist/esm/lib/subcomponent/SelectInput/styles.css +44 -40
- package/dist/esm/lib/subcomponent/SwitchInput/styles.css +90 -86
- package/dist/esm/lib/subcomponent/TextInput/styles.css +30 -26
- package/dist/esm/lib/subcomponent/TextareaInput/styles.css +14 -10
- package/dist/esm/lib/subcomponent/TimeInput/styles.css +19 -15
- package/dist/esm/lib/utils/countries/index.js +3 -3
- package/dist/esm/lib/utils/countries/index.js.map +1 -1
- package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
- package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
- package/dist/esm/lib/utils/formatter/index.js +8 -0
- package/dist/esm/lib/utils/formatter/index.js.map +1 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
- package/dist/esm/lib/utils/formatter/types.js +2 -0
- package/dist/esm/lib/utils/formatter/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/index.js +1 -0
- package/dist/esm/lib/utils/hooks/index.js.map +1 -1
- package/dist/esm/lib/utils/hooks/types.js +2 -0
- package/dist/esm/lib/utils/hooks/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
- package/dist/esm/lib/utils/index.js +6 -2
- package/dist/esm/lib/utils/index.js.map +1 -1
- package/dist/esm/lib/utils/mergeRefs.js +25 -0
- package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
- package/dist/esm/lib/utils/middleware/addRESTValidation.js +1 -1
- package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
- package/dist/types/lib/component/ChoicesField/common/Option/Option.d.ts.map +1 -1
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
- package/dist/types/lib/utils/countries/index.d.ts +0 -3
- package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
- package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
- package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/index.d.ts +6 -0
- package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/types.d.ts +30 -0
- package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/index.d.ts +2 -0
- package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/utils/hooks/types.d.ts +33 -0
- package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
- package/dist/types/lib/utils/index.d.ts +2 -0
- package/dist/types/lib/utils/index.d.ts.map +1 -1
- package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
- package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
- package/package.json +17 -16
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
- package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
- package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
- package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
- package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -23,6 +23,46 @@ The global styles provide the CSS reset, typography baseline, and design tokens
|
|
|
23
23
|
|
|
24
24
|
The package builds on top of `@canonical/react-ds-global`.
|
|
25
25
|
|
|
26
|
+
### How component CSS reaches the page
|
|
27
|
+
|
|
28
|
+
This package puts CSS on the page two ways. `dist/esm/index.css` — the file the snippet above imports — is the package-level stylesheet: the `--form-*` token block, the field grid, the shared input chrome, and `density.css`, which sizes every control to the context and density cell on the root. Each component module then imports its own stylesheet (`import "./styles.css"`), so importing a component is what puts that component's CSS on the page; a bundler collects those imports into the application's CSS. Nothing here is injected at runtime, and a component you never import ships no CSS.
|
|
29
|
+
|
|
30
|
+
The consequence is that the order a bundler happens to emit these sheets in is not something you can rely on, which is what the cascade layer below is for.
|
|
31
|
+
|
|
32
|
+
### Every stylesheet is in `ds.components.global`
|
|
33
|
+
|
|
34
|
+
Every stylesheet under `src/` — the package entry, `density.css`, the 29 component sheets and the density docs example, 32 in all — is wrapped in one cascade layer:
|
|
35
|
+
|
|
36
|
+
```css
|
|
37
|
+
@layer ds.components.global {
|
|
38
|
+
.ds.field-label {
|
|
39
|
+
/* … */
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`@canonical/styles` declares the order of every layer in one statement, and `ds.components.global` sits near the top of it. Two things follow.
|
|
45
|
+
|
|
46
|
+
`ds.components.app`, one layer higher, is the application tiers' — `@canonical/react-ds-app-lxd` and its siblings. None of them is wrapped yet (at the time of writing, no stylesheet under `packages/react/ds-app-*` carries a layer at all); wrapping them is being done package by package alongside this one. Today an app tier still beats this package for the opposite reason — it is unlayered, and unlayered beats layered. What the layer guarantees, once those packages land, is that an app tier's rule for a field or an input this package also styles wins by cascade layer rather than by whichever bundle the loader emitted last.
|
|
47
|
+
|
|
48
|
+
The parent layer `ds.components` sits above both tiers, not between them: a rule written directly into it lands in that layer's implicit final sublayer, which outranks every named sublayer under it. So nothing pragma ships is written directly into `ds.components` — the layout presets in `src/index.css` used to be, in a lone `@layer ds.components` block, and they are in this package's own wrap now like everything else.
|
|
49
|
+
|
|
50
|
+
An application's own **unlayered** CSS now beats every rule in this package, whatever the selectors on either side, because unlayered author rules outrank every layered one. That is CSS working as designed, and it is the deliberate escape hatch: an application that needs to override a form control writes a plain rule and it wins. An application that does *not* want to win by accident puts its CSS in `@layer app`.
|
|
51
|
+
|
|
52
|
+
**Rule for contributors:** every stylesheet under `src/` opens with that wrapper. `@keyframes` and the package's own `:root` token defaults go inside it; `@property` and `@font-face` registrations stay above the block. That last one is a convention, not something the cascade forces: measured in Chromium 151, two registrations sharing a name are sorted exactly like style rules — the one in the higher layer wins whatever the source order, and an unlayered one beats a layered one — for `@property`, `@font-face` and `@keyframes` alike. Keeping registrations above the block is what makes them the document-wide authority they read as, and puts them where someone looking up what a name is registered as will find them. An `@import` stays above the block too — an import is only valid before other rules — and it takes a `layer(ds.components.global)` keyword *only* when the sheet it names is not itself wrapped; `src/index.css` imports `density.css` bare, because `density.css` declares the layer itself and the keyword would nest that declaration into `ds.components.global.ds.components.global`, a sublayer that loses to `index.css`'s own rules. Never reach for `!important` to win a fight — an important declaration inverts the layer order and cannot be arbitrated by layers at all. The `@canonical/styles` README's "Cascade layers" section is the reference for the full order and for what is deliberately left unlayered. The one exemption is `.storybook/styles.css`, which is deliberately outside `src/`: it is the Storybook harness rather than part of the package — never published (`files: ["dist"]`), there to pull this package's CSS into the preview page and add one `.rtl` utility — and staying unlayered is what lets it override the preview.
|
|
53
|
+
|
|
54
|
+
### Components own the box of the natives they render
|
|
55
|
+
|
|
56
|
+
This package renders more native elements than any other: `<input>` in a dozen types, `<select>`, `<textarea>`, `<label>`, `<legend>`, `<fieldset>`, `<button>`. A component that renders a native element is responsible for that element's box — its margin, its width, its `min-width`, its `box-sizing` — and for `::placeholder` where it renders a text input. Anything a component leaves undeclared is filled in by whatever else the host page loads, and on a page that also runs another framework that is a visible bug rather than a default. Declaring the box is being done as its own change; until it lands, treat "the control looks right on our own page" as a weaker guarantee than it sounds.
|
|
57
|
+
|
|
58
|
+
Nothing in this package portals: no `createPortal`, no `appendChild`, no `<dialog>`. The two surfaces that escape their container — the combobox list (`ComboboxInput/common/List/List.tsx:42`) and the colour picker's swatch panel (`ColorInput/ColorInput.tsx:198`) — use the Popover API, which promotes an element to the top layer for painting but leaves it where it is in the DOM. So they stay inside the `.ds` subtree their caller marks, and the element-level layers `@canonical/styles` scopes to that subtree still reach them.
|
|
59
|
+
|
|
60
|
+
### Transitions read the motion tokens
|
|
61
|
+
|
|
62
|
+
Every transition in this package takes its duration from `--motion-duration-fast`, the fast step of the three duration tokens `@canonical/styles` declares, and never from a literal. That is not a tidiness rule. Under `prefers-reduced-motion: reduce` the styles package sets all three duration tokens to `0s`, and that zeroing is the whole of pragma's reduced-motion mechanism: a component's own `transition` declaration keeps its place in the cascade and simply resolves to no time at all. A hard-coded duration is invisible to it and keeps animating for a reader who asked their system not to. This is the code standard `cs:css.properties.values` ("design tokens over raw values") with teeth on it.
|
|
63
|
+
|
|
64
|
+
**Rule for contributors:** no literal duration in a `transition` or an `animation`; a new one reads a token, and a bare `0s` is the one exception, because it already says "no motion". The tokens themselves live in `@canonical/styles` (`motion.css`); if a control needs a step the three do not offer, the step is added there rather than written into a component. Easings are the exception, and a deliberate one: they are still the literal `ease` here rather than `var(--motion-easing-standard)`, because that token is `ease-out` and swapping it is a second change to how the controls feel — it rides on PRA-153 with the missing sub-`fast` duration step.
|
|
65
|
+
|
|
26
66
|
## Dependencies
|
|
27
67
|
|
|
28
68
|
The form system builds on two key libraries:
|