@public-ui/sample-react 4.5.0-rc.8 → 4.6.0-rc.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 +1 -1
- package/package.json +9 -9
- package/src/@shared/demo-input-wc.ts +98 -0
- package/src/components/breadcrumb/json-links.tsx +28 -0
- package/src/components/breadcrumb/routes.ts +2 -0
- package/src/components/button/routes.ts +2 -0
- package/src/components/button/tooltip-align.tsx +30 -0
- package/src/components/card/closer-callback.tsx +43 -0
- package/src/components/card/routes.ts +2 -0
- package/src/components/dialog/with-alert.tsx +7 -1
- package/src/components/input-radio/option-values.tsx +46 -0
- package/src/components/input-radio/routes.ts +2 -0
- package/src/components/input-text/aria-details.tsx +101 -3
- package/src/components/meter/clamped.tsx +27 -0
- package/src/components/meter/routes.ts +2 -0
- package/src/components/popover-button/align.tsx +31 -0
- package/src/components/popover-button/routes.ts +2 -0
- package/src/components/single-select/option-values.tsx +46 -0
- package/src/components/single-select/routes.ts +2 -0
- package/src/components/table/stateless-with-settings-menu.tsx +1 -0
- package/src/scenarios/label-lang.tsx +156 -0
- package/src/scenarios/routes.ts +2 -2
- package/src/scenarios/sample-form-with-validation.tsx +0 -160
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# KoliBri - React Sample App
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@public-ui/components)
|
|
4
|
-
[](https://github.com/public-ui/kolibri/blob/
|
|
4
|
+
[](https://github.com/public-ui/kolibri/blob/develop/LICENSE)
|
|
5
5
|
[](https://www.npmjs.com/package/@public-ui/sample-react)
|
|
6
6
|
[](https://github.com/public-ui/kolibri/issues)
|
|
7
7
|
[](https://github.com/public-ui/kolibri/pulls)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@public-ui/sample-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0-rc.0",
|
|
4
4
|
"description": "This app contains samples for the KoliBri/Public UI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "EUPL-1.2",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"url": "https://github.com/public-ui/kolibri"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@hookform/resolvers": "5.9.
|
|
13
|
-
"@stencil/core": "4.
|
|
12
|
+
"@hookform/resolvers": "5.9.2",
|
|
13
|
+
"@stencil/core": "4.45.2",
|
|
14
14
|
"@types/node": "26.4.0",
|
|
15
15
|
"@types/papaparse": "5.5.2",
|
|
16
16
|
"papaparse": "5.7.0",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"tslib": "2.8.1",
|
|
20
20
|
"typescript": "5.9.3",
|
|
21
21
|
"world_countries_lists": "3.3.0",
|
|
22
|
-
"zod": "4.6.
|
|
23
|
-
"@public-ui/react-hook-form-adapter": "4.
|
|
24
|
-
"@public-ui/react-v19": "4.
|
|
22
|
+
"zod": "4.6.7",
|
|
23
|
+
"@public-ui/react-hook-form-adapter": "4.6.0-rc.0",
|
|
24
|
+
"@public-ui/react-v19": "4.6.0-rc.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "19.2.18",
|
|
28
28
|
"@types/react-dom": "19.2.5",
|
|
29
29
|
"adopted-style-sheets": "1.1.9-rc.25",
|
|
30
30
|
"eslint": "9.39.5",
|
|
31
|
-
"knip": "6.
|
|
32
|
-
"prettier": "3.9.
|
|
31
|
+
"knip": "6.42.1",
|
|
32
|
+
"prettier": "3.9.10",
|
|
33
33
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
34
34
|
"stylelint": "17.16.0"
|
|
35
35
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"react": "19.2.8",
|
|
38
38
|
"react-dom": "19.2.8",
|
|
39
39
|
"react-router": "8.4.0",
|
|
40
|
-
"@public-ui/components": "4.
|
|
40
|
+
"@public-ui/components": "4.6.0-rc.0"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"assets",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Web Component demos for aria-details across Shadow DOM boundaries — the control group for
|
|
3
|
+
* the KoliBri `_ariaDetails` implementation: if a case announces in a screen reader while the
|
|
4
|
+
* KoliBri fields do not, the gap is ours; if the native shadow case is silent too, the platform
|
|
5
|
+
* (e.g. Safari/VoiceOver without element reflection) does not support the relation yet.
|
|
6
|
+
*
|
|
7
|
+
* demo-input-light — no shadow root; the input's aria-details IDREF resolves
|
|
8
|
+
* directly in the document tree (no boundary to cross).
|
|
9
|
+
*
|
|
10
|
+
* demo-input-shadow (shadow: open)
|
|
11
|
+
* └─ <input> in the shadow root; external elements are bridged via the
|
|
12
|
+
* input's ariaDetailsElements (ARIA element reflection) — the same
|
|
13
|
+
* mechanism the KoliBri form fields use.
|
|
14
|
+
*
|
|
15
|
+
* Import this module once anywhere in the app; the guard prevents duplicate registration.
|
|
16
|
+
*/
|
|
17
|
+
type DetailsTarget = HTMLElement & { ariaDetailsElements?: HTMLElement[] | null };
|
|
18
|
+
|
|
19
|
+
const INPUT_STYLES = `
|
|
20
|
+
label { display: block; }
|
|
21
|
+
span { display: block; margin-bottom: 4px; }
|
|
22
|
+
input { border: 1px solid #888; padding: 4px 8px; font: inherit; }
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const resolveExternal = (host: HTMLElement, value: string | null): HTMLElement[] => {
|
|
26
|
+
const root = host.getRootNode() as Document | ShadowRoot;
|
|
27
|
+
const getById = (id: string): HTMLElement | null => (root instanceof ShadowRoot ? root.querySelector(`#${CSS.escape(id)}`) : document.getElementById(id));
|
|
28
|
+
return (value ?? '')
|
|
29
|
+
.trim()
|
|
30
|
+
.split(/\s+/)
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.map(getById)
|
|
33
|
+
.filter((el): el is HTMLElement => el !== null);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Web Component WITHOUT shadow root. The input's aria-details IDREF resolves in the host document. */
|
|
37
|
+
class DemoInputLight extends HTMLElement {
|
|
38
|
+
static get observedAttributes() {
|
|
39
|
+
return ['aria-details'];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
this._render();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
attributeChangedCallback() {
|
|
47
|
+
if (this.isConnected) this._render();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_render() {
|
|
51
|
+
this.innerHTML = `<style>${INPUT_STYLES}</style><label><span>Native input, no shadow root</span><input aria-label="Native light input"></label>`;
|
|
52
|
+
const input = this.querySelector('input')!;
|
|
53
|
+
const details = this.getAttribute('aria-details');
|
|
54
|
+
if (details) {
|
|
55
|
+
input.setAttribute('aria-details', details);
|
|
56
|
+
} else {
|
|
57
|
+
input.removeAttribute('aria-details');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Outer part — shadow: open; bridges the external details via element reflection on the native input. */
|
|
63
|
+
class DemoInputShadow extends HTMLElement {
|
|
64
|
+
constructor() {
|
|
65
|
+
super();
|
|
66
|
+
this.attachShadow({ mode: 'open' });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static get observedAttributes() {
|
|
70
|
+
return ['aria-details'];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
connectedCallback() {
|
|
74
|
+
this.shadowRoot!.innerHTML = `<style>${INPUT_STYLES}</style><label><span>Native input, inside a shadow root</span><input aria-label="Native shadow input"></label>`;
|
|
75
|
+
this._sync(this.getAttribute('aria-details'));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
attributeChangedCallback(_name: string, _old: string | null, newValue: string | null) {
|
|
79
|
+
if (this.isConnected) this._sync(newValue);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_sync(value: string | null) {
|
|
83
|
+
const input = this.shadowRoot!.querySelector('input') as unknown as DetailsTarget;
|
|
84
|
+
if (!('ariaDetailsElements' in input)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
input.ariaDetailsElements = resolveExternal(this, value);
|
|
89
|
+
} catch (_) {
|
|
90
|
+
/* ariaDetailsElements not supported */
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof customElements !== 'undefined') {
|
|
96
|
+
if (!customElements.get('demo-input-light')) customElements.define('demo-input-light', DemoInputLight);
|
|
97
|
+
if (!customElements.get('demo-input-shadow')) customElements.define('demo-input-shadow', DemoInputShadow);
|
|
98
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { KolBreadcrumb } from '@public-ui/react-v19';
|
|
4
|
+
import { SampleBlock } from '../SampleBlock';
|
|
5
|
+
import { SampleDescription } from '../SampleDescription';
|
|
6
|
+
|
|
7
|
+
import type { FC } from 'react';
|
|
8
|
+
|
|
9
|
+
const LINKS_AS_JSON = JSON.stringify([
|
|
10
|
+
{ _label: 'Homepage', _icons: 'kolicon-house', _hideLabel: true, _href: '#/back-page' },
|
|
11
|
+
{ _label: 'Services', _href: '#/back-page' },
|
|
12
|
+
{ _label: 'Apply for a permit', _href: '#/back-page' },
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
export const BreadcrumbJsonLinks: FC = () => (
|
|
16
|
+
<>
|
|
17
|
+
<SampleDescription>
|
|
18
|
+
<p>
|
|
19
|
+
The <code>_links</code> of KolBreadcrumb can also be passed as JSON string, e.g. through an HTML attribute; the result is the same as with an array.
|
|
20
|
+
Every entry needs an <code>_href</code>, and an entry with <code>_hideLabel</code> shows only its icon.
|
|
21
|
+
</p>
|
|
22
|
+
</SampleDescription>
|
|
23
|
+
|
|
24
|
+
<SampleBlock id="json-links" narrow>
|
|
25
|
+
<KolBreadcrumb _label="Breadcrumb from a JSON string" _links={LINKS_AS_JSON}></KolBreadcrumb>
|
|
26
|
+
</SampleBlock>
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Routes } from '../../shares/types';
|
|
2
2
|
import { BreadcrumbBasic } from './basic';
|
|
3
|
+
import { BreadcrumbJsonLinks } from './json-links';
|
|
3
4
|
|
|
4
5
|
export const BREADCRUMB_ROUTES: Routes = {
|
|
5
6
|
breadcrumb: {
|
|
6
7
|
basic: BreadcrumbBasic,
|
|
8
|
+
'json-links': BreadcrumbJsonLinks,
|
|
7
9
|
},
|
|
8
10
|
};
|
|
@@ -13,6 +13,7 @@ import { ButtonPinToggle } from './pin-toggle';
|
|
|
13
13
|
import { ButtonRowReverseTooltip } from './row-reverse-tooltip';
|
|
14
14
|
import { ButtonShortKey } from './short-key';
|
|
15
15
|
import { ButtonSpinner } from './spinner';
|
|
16
|
+
import { ButtonTooltipAlign } from './tooltip-align';
|
|
16
17
|
import { ButtonWidth } from './width';
|
|
17
18
|
|
|
18
19
|
export const BUTTON_ROUTES: Routes = {
|
|
@@ -30,6 +31,7 @@ export const BUTTON_ROUTES: Routes = {
|
|
|
30
31
|
'short-key': ButtonShortKey,
|
|
31
32
|
'expert-slot': ButtonExpertSlot,
|
|
32
33
|
'row-reverse-tooltip': ButtonRowReverseTooltip,
|
|
34
|
+
'tooltip-align': ButtonTooltipAlign,
|
|
33
35
|
'focus-options': ButtonFocusOptions,
|
|
34
36
|
'fixed-grid': ButtonInFixedGrid,
|
|
35
37
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { KolButton, KolLink } from '@public-ui/react-v19';
|
|
4
|
+
import { SampleBlock } from '../SampleBlock';
|
|
5
|
+
import { SampleDescription } from '../SampleDescription';
|
|
6
|
+
|
|
7
|
+
import type { AlignPropType } from '@public-ui/components';
|
|
8
|
+
import type { FC } from 'react';
|
|
9
|
+
|
|
10
|
+
const ALIGNMENTS: AlignPropType[] = ['top', 'right', 'bottom', 'left'];
|
|
11
|
+
|
|
12
|
+
export const ButtonTooltipAlign: FC = () => (
|
|
13
|
+
<>
|
|
14
|
+
<SampleDescription>
|
|
15
|
+
<p>
|
|
16
|
+
With a hidden label, the label is shown as tooltip on hover and focus. <code>_tooltipAlign</code> places it on one of the four sides. A button places it
|
|
17
|
+
on top by default, a link on the right.
|
|
18
|
+
</p>
|
|
19
|
+
<p>Hover or focus the elements to see the tooltips.</p>
|
|
20
|
+
</SampleDescription>
|
|
21
|
+
|
|
22
|
+
<SampleBlock id="tooltip-align" className="grid grid-cols-2 gap-16 p-16 justify-items-center" skipSnapshot>
|
|
23
|
+
{ALIGNMENTS.map((align) => (
|
|
24
|
+
<KolButton key={align} _label={`Tooltip ${align}`} _icons="kolicon-alert-info" _hideLabel _tooltipAlign={align} />
|
|
25
|
+
))}
|
|
26
|
+
<KolButton _label="Button with default (top)" _icons="kolicon-check" _hideLabel />
|
|
27
|
+
<KolLink _label="Link with default (right)" _icons="kolicon-link" _hideLabel _href="#/back-page" />
|
|
28
|
+
</SampleBlock>
|
|
29
|
+
</>
|
|
30
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KolButton, KolCard } from '@public-ui/react-v19';
|
|
4
|
+
|
|
5
|
+
import type { FC } from 'react';
|
|
6
|
+
import { SampleBlock } from '../SampleBlock';
|
|
7
|
+
import { SampleDescription } from '../SampleDescription';
|
|
8
|
+
|
|
9
|
+
export const CardCloserCallback: FC = () => {
|
|
10
|
+
const [open, setOpen] = useState(true);
|
|
11
|
+
const [closeCount, setCloseCount] = useState(0);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<SampleDescription>
|
|
16
|
+
<p>
|
|
17
|
+
The close button of KolCard calls <code>_on.onClose</code>. The card does not hide itself; the application decides what happens. Here the callback
|
|
18
|
+
removes the card, and the button below brings it back.
|
|
19
|
+
</p>
|
|
20
|
+
</SampleDescription>
|
|
21
|
+
|
|
22
|
+
<SampleBlock id="closer-callback" className="grid gap-4" skipSnapshot>
|
|
23
|
+
{open ? (
|
|
24
|
+
<KolCard
|
|
25
|
+
_label="Card that closes itself"
|
|
26
|
+
_hasCloser
|
|
27
|
+
_on={{
|
|
28
|
+
onClose: () => {
|
|
29
|
+
setOpen(false);
|
|
30
|
+
setCloseCount((count) => count + 1);
|
|
31
|
+
},
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<p>Click the close button to remove the card.</p>
|
|
35
|
+
</KolCard>
|
|
36
|
+
) : (
|
|
37
|
+
<KolButton _label="Show the card again" _on={{ onClick: () => setOpen(true) }} />
|
|
38
|
+
)}
|
|
39
|
+
<p aria-live="polite">Closed {closeCount} time(s).</p>
|
|
40
|
+
</SampleBlock>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Routes } from '../../shares/types';
|
|
2
2
|
import { CardBasic } from './basic';
|
|
3
|
+
import { CardCloserCallback } from './closer-callback';
|
|
3
4
|
import { CardHeadlines } from './headlines';
|
|
4
5
|
import { CardLinked } from './linked';
|
|
5
6
|
|
|
6
7
|
export const CARD_ROUTES: Routes = {
|
|
7
8
|
card: {
|
|
8
9
|
basic: CardBasic,
|
|
10
|
+
'closer-callback': CardCloserCallback,
|
|
9
11
|
headlines: CardHeadlines,
|
|
10
12
|
linked: CardLinked,
|
|
11
13
|
},
|
|
@@ -47,7 +47,13 @@ export const DialogWithAlert: FC = () => {
|
|
|
47
47
|
<div className="grid gap-4">
|
|
48
48
|
<div>
|
|
49
49
|
<KolButton _label="Open dialog with alert" _on={onOpenDialog} />
|
|
50
|
-
<KolDialog
|
|
50
|
+
<KolDialog
|
|
51
|
+
ref={dialogRef}
|
|
52
|
+
_label="Dialog with KolAlert inside"
|
|
53
|
+
_variant="card"
|
|
54
|
+
_width="40%"
|
|
55
|
+
_on={{ onToggle: (open) => console.log('Dialog onToggle triggered!', open), onClose: onDialogClose }}
|
|
56
|
+
>
|
|
51
57
|
<div className="p-4">
|
|
52
58
|
{showAlert && (
|
|
53
59
|
<KolAlert _label="Closeable alert" _type="info" _variant="card" _hasCloser _on={{ onClose: onAlertClose }}>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { KolInputRadio } from '@public-ui/react-v19';
|
|
5
|
+
|
|
6
|
+
import type { RadioOption, StencilUnknown } from '@public-ui/components';
|
|
7
|
+
import { SampleBlock } from '../SampleBlock';
|
|
8
|
+
import { SampleDescription } from '../SampleDescription';
|
|
9
|
+
|
|
10
|
+
/** Number labels are accepted and shown as text. */
|
|
11
|
+
const NUMBER_LABEL_OPTIONS = [
|
|
12
|
+
{ label: 1, value: 1, hint: 'One person' },
|
|
13
|
+
{ label: 2, value: 2, hint: 'Two persons' },
|
|
14
|
+
{ label: 3, value: 3, hint: 'Three persons' },
|
|
15
|
+
] as unknown as RadioOption<StencilUnknown>[];
|
|
16
|
+
|
|
17
|
+
/** Without a `value`, an option uses its label as value; the JSON string form allows to leave it out. */
|
|
18
|
+
const LABEL_AS_VALUE_OPTIONS = JSON.stringify([{ label: 'Mrs.' }, { label: 'Mr.' }, { label: 'Company', value: 'company' }]);
|
|
19
|
+
|
|
20
|
+
const FALSY_VALUE_OPTIONS: RadioOption<StencilUnknown>[] = [
|
|
21
|
+
{ label: 'No', value: false },
|
|
22
|
+
{ label: 'Yes', value: true },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const InputRadioOptionValues: FC = () => (
|
|
26
|
+
<>
|
|
27
|
+
<SampleDescription>
|
|
28
|
+
<p>
|
|
29
|
+
The options of KolInputRadio accept a number as <code>label</code>, which is shown as text, and an optional <code>hint</code> per option. An option
|
|
30
|
+
without <code>value</code> uses its label as value, and a falsy value such as <code>false</code> is selected like any other value.
|
|
31
|
+
</p>
|
|
32
|
+
</SampleDescription>
|
|
33
|
+
|
|
34
|
+
<div className="grid gap-4">
|
|
35
|
+
<SampleBlock id="number-labels">
|
|
36
|
+
<KolInputRadio _label="Number of persons (number labels with hints)" _options={NUMBER_LABEL_OPTIONS} _value={2} />
|
|
37
|
+
</SampleBlock>
|
|
38
|
+
<SampleBlock id="label-as-value">
|
|
39
|
+
<KolInputRadio _label="Salutation (options without value)" _options={LABEL_AS_VALUE_OPTIONS} _value="Mr." _orientation="horizontal" />
|
|
40
|
+
</SampleBlock>
|
|
41
|
+
<SampleBlock id="falsy-value">
|
|
42
|
+
<KolInputRadio _label="Newsletter (value false selected)" _options={FALSY_VALUE_OPTIONS} _value={false} _orientation="horizontal" />
|
|
43
|
+
</SampleBlock>
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
@@ -3,6 +3,7 @@ import { InputRadioBasic } from './basic';
|
|
|
3
3
|
import { InputRadioOnInputOnChange } from './get-value';
|
|
4
4
|
import { InputRadioHorizontal } from './horizontal';
|
|
5
5
|
import { InputRadioObjectValue } from './objectValue';
|
|
6
|
+
import { InputRadioOptionValues } from './option-values';
|
|
6
7
|
|
|
7
8
|
export const INPUT_RADIO_ROUTES: Routes = {
|
|
8
9
|
'input-radio': {
|
|
@@ -10,5 +11,6 @@ export const INPUT_RADIO_ROUTES: Routes = {
|
|
|
10
11
|
'get-value': InputRadioOnInputOnChange,
|
|
11
12
|
horizontal: InputRadioHorizontal,
|
|
12
13
|
object: InputRadioObjectValue,
|
|
14
|
+
'option-values': InputRadioOptionValues,
|
|
13
15
|
},
|
|
14
16
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KolCombobox, KolInputText, KolSelect, KolTextarea } from '@public-ui/react-v19';
|
|
2
2
|
import type { FC } from 'react';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import '../../@shared/demo-input-wc';
|
|
4
5
|
import { SampleBlock } from '../SampleBlock';
|
|
5
6
|
import { SampleDescription } from '../SampleDescription';
|
|
6
7
|
|
|
@@ -12,13 +13,47 @@ export const InputTextAriaDetails: FC = () => (
|
|
|
12
13
|
below reference the same details box via their <code>_ariaDetails</code> prop.
|
|
13
14
|
</p>
|
|
14
15
|
<p>
|
|
15
|
-
The
|
|
16
|
-
|
|
16
|
+
The native inputs above are the control group: the first one declares a plain <code>aria-details</code> IDREF in the same tree, the second one is
|
|
17
|
+
wrapped in a native web component whose shadow input bridges the reference via <code>ariaDetailsElements</code> — the same mechanism KoliBri uses. If a
|
|
18
|
+
native case announces the details in a screen reader while the KoliBri fields do not, the gap is in KoliBri; if the native shadow case is silent too,
|
|
19
|
+
the platform does not support the relation across the boundary yet (Safari/VoiceOver lacks element reflection — verify with NVDA or JAWS on Chromium
|
|
20
|
+
instead).
|
|
21
|
+
</p>
|
|
22
|
+
<p>
|
|
23
|
+
The last example below replicates the{' '}
|
|
24
|
+
<a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-details">
|
|
25
|
+
MDN example for <code>aria-details</code>
|
|
26
|
+
</a>
|
|
27
|
+
: a term references its definition and an explanatory link — the canonical use outside of forms the attribute was designed for.
|
|
17
28
|
</p>
|
|
18
29
|
</SampleDescription>
|
|
19
30
|
|
|
20
31
|
<SampleBlock id="aria-details" className="grid gap-8">
|
|
21
|
-
{/*
|
|
32
|
+
{/* Native reference implementations — the control group */}
|
|
33
|
+
<div className="grid gap-4 p-4 border border-gray-300 rounded">
|
|
34
|
+
<h2 className="text-lg font-semibold">Native reference implementations</h2>
|
|
35
|
+
|
|
36
|
+
<div>
|
|
37
|
+
<label className="block">
|
|
38
|
+
<span className="block mb-2">Native HTML input (no web component)</span>
|
|
39
|
+
<input aria-details="details-box-native-light" aria-label="Native light input" className="border border-gray-500 p-2" />
|
|
40
|
+
</label>
|
|
41
|
+
<div id="details-box-native-light" className="mt-2 p-2 bg-blue-50 border-l-4 border-blue-400 rounded text-sm text-blue-800">
|
|
42
|
+
Details for the plain native input: the IDREF resolves in the same tree — no boundary to cross.
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div>{React.createElement('demo-input-light', { 'aria-details': 'details-box-native-light' })}</div>
|
|
47
|
+
|
|
48
|
+
<div>
|
|
49
|
+
{React.createElement('demo-input-shadow', { 'aria-details': 'details-box-native-shadow' })}
|
|
50
|
+
<div id="details-box-native-shadow" className="mt-2 p-2 bg-blue-50 border-l-4 border-blue-400 rounded text-sm text-blue-800">
|
|
51
|
+
Details for the native shadow input: the reference crosses the boundary via <code>ariaDetailsElements</code> on the input.
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
{/* KoliBri form fields */}
|
|
22
57
|
<div className="grid gap-4 p-4 border border-gray-300 rounded">
|
|
23
58
|
<h2 className="text-lg font-semibold">Form Inputs with Shared Details</h2>
|
|
24
59
|
|
|
@@ -57,6 +92,69 @@ export const InputTextAriaDetails: FC = () => (
|
|
|
57
92
|
</li>
|
|
58
93
|
</ul>
|
|
59
94
|
</div>
|
|
95
|
+
|
|
96
|
+
{/* MDN example — term & definition (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-details) */}
|
|
97
|
+
<div className="grid gap-4 p-4 border border-gray-300 rounded">
|
|
98
|
+
<h2 className="text-lg font-semibold">MDN example: term & definition</h2>
|
|
99
|
+
|
|
100
|
+
<p>
|
|
101
|
+
The term below references two targets: the definition paragraph and the explanatory image link. Screen reader support for <code>aria-details</code> is
|
|
102
|
+
heavily fragmented — check <a href="https://a11ysupport.io/tech/aria/aria-details_attribute">a11ysupport.io</a> before relying on it.
|
|
103
|
+
</p>
|
|
104
|
+
|
|
105
|
+
<p>
|
|
106
|
+
The <strong>cubic-bezier()</strong> functional notation defines a cubic{' '}
|
|
107
|
+
<span role="term" aria-details="bezier bezImg" className="underline decoration-dotted underline-offset-4">
|
|
108
|
+
Bézier curve
|
|
109
|
+
</span>
|
|
110
|
+
. As these curves are continuous, they are often used to smooth down the start and end of the curve and are therefore sometimes called easing
|
|
111
|
+
functions.
|
|
112
|
+
</p>
|
|
113
|
+
|
|
114
|
+
<p role="definition" id="bezier" className="p-2 bg-blue-50 border-l-4 border-blue-400 rounded text-sm text-blue-800">
|
|
115
|
+
A <strong>Bézier curve</strong>, (Pronounced \ ˈbe-zē-ˌā \ <i aria-description="English pronunciation">BEH-zee-ay</i>) is a mathematically described
|
|
116
|
+
curve used in computer graphics and animation. The curve is defined by a set of control points with a minimum of two. Web related graphics and
|
|
117
|
+
animations use Cubic Béziers, which are curves with four control points P<sub>0</sub>, P<sub>1</sub>, P<sub>2</sub>, and P<sub>3</sub>.
|
|
118
|
+
</p>
|
|
119
|
+
|
|
120
|
+
<a
|
|
121
|
+
href="https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function"
|
|
122
|
+
id="bezImg"
|
|
123
|
+
aria-label="Explanation of Bézier curve in CSS easing functions"
|
|
124
|
+
target="_blank"
|
|
125
|
+
rel="noreferrer"
|
|
126
|
+
className="block w-fit"
|
|
127
|
+
>
|
|
128
|
+
<svg
|
|
129
|
+
width="200"
|
|
130
|
+
height="160"
|
|
131
|
+
viewBox="0 0 200 160"
|
|
132
|
+
role="img"
|
|
133
|
+
aria-label="Cubic Bézier curve showing 4 control points."
|
|
134
|
+
className="border border-gray-400 rounded bg-white"
|
|
135
|
+
>
|
|
136
|
+
<path d="M 20 130 C 60 10, 140 150, 180 30" fill="none" stroke="#0075ff" strokeWidth="2" />
|
|
137
|
+
<line x1="20" y1="130" x2="60" y2="10" stroke="#888" strokeDasharray="4 3" />
|
|
138
|
+
<line x1="140" y1="150" x2="180" y2="30" stroke="#888" strokeDasharray="4 3" />
|
|
139
|
+
<circle cx="20" cy="130" r="4" fill="#0075ff" />
|
|
140
|
+
<circle cx="60" cy="10" r="4" fill="#888" />
|
|
141
|
+
<circle cx="140" cy="150" r="4" fill="#888" />
|
|
142
|
+
<circle cx="180" cy="30" r="4" fill="#0075ff" />
|
|
143
|
+
<text x="12" y="148" fontSize="12" fill="#202020">
|
|
144
|
+
P0
|
|
145
|
+
</text>
|
|
146
|
+
<text x="60" y="24" fontSize="12" fill="#202020" textAnchor="middle">
|
|
147
|
+
P1
|
|
148
|
+
</text>
|
|
149
|
+
<text x="140" y="144" fontSize="12" fill="#202020" textAnchor="middle">
|
|
150
|
+
P2
|
|
151
|
+
</text>
|
|
152
|
+
<text x="184" y="20" fontSize="12" fill="#202020" textAnchor="end">
|
|
153
|
+
P3
|
|
154
|
+
</text>
|
|
155
|
+
</svg>
|
|
156
|
+
</a>
|
|
157
|
+
</div>
|
|
60
158
|
</SampleBlock>
|
|
61
159
|
</>
|
|
62
160
|
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { KolMeter } from '@public-ui/react-v19';
|
|
2
|
+
import type { FC } from 'react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { SampleBlock } from '../SampleBlock';
|
|
5
|
+
import { SampleDescription } from '../SampleDescription';
|
|
6
|
+
|
|
7
|
+
export const MeterClamped: FC = () => (
|
|
8
|
+
<>
|
|
9
|
+
<SampleDescription>
|
|
10
|
+
<p>
|
|
11
|
+
A <code>_value</code> outside the range of <code>_min</code> and <code>_max</code> is clamped into it: a value above <code>_max</code> renders as{' '}
|
|
12
|
+
<code>_max</code>, a value below <code>_min</code> as <code>_min</code>.
|
|
13
|
+
</p>
|
|
14
|
+
</SampleDescription>
|
|
15
|
+
|
|
16
|
+
<div className="grid gap-8">
|
|
17
|
+
<SampleBlock id="clamped" heading="Values outside the range">
|
|
18
|
+
<div className="flex flex-col gap-4">
|
|
19
|
+
<KolMeter _label="Value 140, maximum 100 (shows 100)" _max={100} _value={140} _unit="%" />
|
|
20
|
+
<KolMeter _label="Value 60, range 0 to 100 (unchanged)" _max={100} _value={60} _unit="%" />
|
|
21
|
+
<KolMeter _label="Value -20, minimum 0 (shows 0)" _min={0} _max={100} _value={-20} _unit="%" />
|
|
22
|
+
<KolMeter _label="Value -40 °C, range -20 to 60 °C (shows -20 °C)" _min={-20} _max={60} _value={-40} _unit="°C" />
|
|
23
|
+
</div>
|
|
24
|
+
</SampleBlock>
|
|
25
|
+
</div>
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Routes } from '../../shares/types';
|
|
2
2
|
import { MeterBasic } from './basic';
|
|
3
|
+
import { MeterClamped } from './clamped';
|
|
3
4
|
import { MeterDynamic } from './dynamic';
|
|
4
5
|
import { MeterOptimum } from './optimum';
|
|
5
6
|
import { MeterOrientation } from './orientation';
|
|
@@ -7,6 +8,7 @@ import { MeterOrientation } from './orientation';
|
|
|
7
8
|
export const METER_ROUTES: Routes = {
|
|
8
9
|
meter: {
|
|
9
10
|
basic: MeterBasic,
|
|
11
|
+
clamped: MeterClamped,
|
|
10
12
|
dynamic: MeterDynamic,
|
|
11
13
|
optimum: MeterOptimum,
|
|
12
14
|
orientation: MeterOrientation,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { KolPopoverButton } from '@public-ui/react-v19';
|
|
2
|
+
import type { FC } from 'react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import type { AlignPropType } from '@public-ui/components';
|
|
6
|
+
import { SampleBlock } from '../SampleBlock';
|
|
7
|
+
import { SampleDescription } from '../SampleDescription';
|
|
8
|
+
|
|
9
|
+
const ALIGNMENTS: AlignPropType[] = ['top', 'right', 'bottom', 'left'];
|
|
10
|
+
|
|
11
|
+
export const PopoverButtonAlign: FC = () => (
|
|
12
|
+
<>
|
|
13
|
+
<SampleDescription>
|
|
14
|
+
<p>
|
|
15
|
+
<code>_popoverAlign</code> places the popover on one of the four sides of the button; the default is <code>bottom</code>. If there is not enough space,
|
|
16
|
+
the popover moves to the opposite side.
|
|
17
|
+
</p>
|
|
18
|
+
<p>Open the buttons one after the other to compare the positions.</p>
|
|
19
|
+
</SampleDescription>
|
|
20
|
+
|
|
21
|
+
<SampleBlock id="popover-align" className="grid grid-cols-2 gap-32 p-32 justify-items-center" skipSnapshot>
|
|
22
|
+
{ALIGNMENTS.map((align) => (
|
|
23
|
+
<KolPopoverButton key={align} _label={`Popover ${align}`} _popoverAlign={align}>
|
|
24
|
+
<p className="m-0 p-2 bg-white">
|
|
25
|
+
Popover placed <strong>{align}</strong>.
|
|
26
|
+
</p>
|
|
27
|
+
</KolPopoverButton>
|
|
28
|
+
))}
|
|
29
|
+
</SampleBlock>
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Routes } from '../../shares/types';
|
|
2
|
+
import { PopoverButtonAlign } from './align';
|
|
2
3
|
import { PopoverButtonBasic } from './basic';
|
|
3
4
|
import { PopoverButtonInline } from './inline';
|
|
4
5
|
|
|
5
6
|
export const POPOVER_BUTTON_ROUTES: Routes = {
|
|
6
7
|
'popover-button': {
|
|
8
|
+
align: PopoverButtonAlign,
|
|
7
9
|
basic: PopoverButtonBasic,
|
|
8
10
|
inline: PopoverButtonInline,
|
|
9
11
|
},
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { KolSingleSelect } from '@public-ui/react-v19';
|
|
5
|
+
|
|
6
|
+
import type { Option, StencilUnknown } from '@public-ui/components';
|
|
7
|
+
import { SampleBlock } from '../SampleBlock';
|
|
8
|
+
import { SampleDescription } from '../SampleDescription';
|
|
9
|
+
|
|
10
|
+
const FALSY_VALUE_OPTIONS: Option<StencilUnknown>[] = [
|
|
11
|
+
{ label: 'Zero', value: 0 },
|
|
12
|
+
{ label: 'No', value: false },
|
|
13
|
+
{ label: 'Empty string', value: '' },
|
|
14
|
+
{ label: 'One', value: 1 },
|
|
15
|
+
{ label: 'Two (disabled)', value: 2, disabled: true },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/** Number labels are accepted and shown as text. */
|
|
19
|
+
const NUMBER_LABEL_OPTIONS = [
|
|
20
|
+
{ label: 2024, value: 2024 },
|
|
21
|
+
{ label: 2025, value: 2025 },
|
|
22
|
+
{ label: 2026, value: 2026 },
|
|
23
|
+
] as unknown as Option<StencilUnknown>[];
|
|
24
|
+
|
|
25
|
+
export const SingleSelectOptionValues: FC = () => (
|
|
26
|
+
<>
|
|
27
|
+
<SampleDescription>
|
|
28
|
+
<p>
|
|
29
|
+
The options of KolSingleSelect accept any value, also falsy ones such as <code>0</code>, <code>false</code> or an empty string; the selected option is
|
|
30
|
+
found by its value. A number as <code>label</code> is shown as text. Disabled options stay visible in the list but can not be selected.
|
|
31
|
+
</p>
|
|
32
|
+
</SampleDescription>
|
|
33
|
+
|
|
34
|
+
<div className="grid gap-4">
|
|
35
|
+
<SampleBlock id="falsy-zero">
|
|
36
|
+
<KolSingleSelect _label="Value 0 selected" _options={FALSY_VALUE_OPTIONS} _value={0} />
|
|
37
|
+
</SampleBlock>
|
|
38
|
+
<SampleBlock id="falsy-false">
|
|
39
|
+
<KolSingleSelect _label="Value false selected" _options={FALSY_VALUE_OPTIONS} _value={false} />
|
|
40
|
+
</SampleBlock>
|
|
41
|
+
<SampleBlock id="number-labels">
|
|
42
|
+
<KolSingleSelect _label="Number labels (year)" _options={NUMBER_LABEL_OPTIONS} _value={2025} />
|
|
43
|
+
</SampleBlock>
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
@@ -2,11 +2,13 @@ import type { Routes } from '../../shares/types';
|
|
|
2
2
|
import { SingleSelectBasic } from './basic';
|
|
3
3
|
import { SingleSelectOnInputOnChange } from './get-value';
|
|
4
4
|
import { SingleSelectLazyLoaded } from './lazy-loaded';
|
|
5
|
+
import { SingleSelectOptionValues } from './option-values';
|
|
5
6
|
|
|
6
7
|
export const SINGLE_SELECT_ROUTES: Routes = {
|
|
7
8
|
'single-select': {
|
|
8
9
|
basic: SingleSelectBasic,
|
|
9
10
|
'get-value': SingleSelectOnInputOnChange,
|
|
10
11
|
'lazy-loaded': SingleSelectLazyLoaded,
|
|
12
|
+
'option-values': SingleSelectOptionValues,
|
|
11
13
|
},
|
|
12
14
|
};
|
|
@@ -106,6 +106,7 @@ export const TableStatelessWithSettingsMenu: FC = () => (
|
|
|
106
106
|
_on={{
|
|
107
107
|
onSort: (_e, payload) => console.log('sort', payload),
|
|
108
108
|
onSelectionChange: (_e, value) => console.log('selection', value),
|
|
109
|
+
onChangeHeaderCells: (_e, value) => console.log('header settings changed', value),
|
|
109
110
|
}}
|
|
110
111
|
/>
|
|
111
112
|
</>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
KolAccordion,
|
|
5
|
+
KolAlert,
|
|
6
|
+
KolBadge,
|
|
7
|
+
KolBreadcrumb,
|
|
8
|
+
KolButton,
|
|
9
|
+
KolButtonLink,
|
|
10
|
+
KolCard,
|
|
11
|
+
KolDetails,
|
|
12
|
+
KolHeading,
|
|
13
|
+
KolInputCheckbox,
|
|
14
|
+
KolInputText,
|
|
15
|
+
KolLink,
|
|
16
|
+
KolLinkButton,
|
|
17
|
+
KolMeter,
|
|
18
|
+
KolNav,
|
|
19
|
+
KolPopoverButton,
|
|
20
|
+
KolProgress,
|
|
21
|
+
KolQuote,
|
|
22
|
+
KolTableStateful,
|
|
23
|
+
KolTabs,
|
|
24
|
+
KolToolbar,
|
|
25
|
+
KolTree,
|
|
26
|
+
KolTreeItem,
|
|
27
|
+
} from '@public-ui/react-v19';
|
|
28
|
+
import { SampleBlock } from '../components/SampleBlock';
|
|
29
|
+
import { SampleDescription } from '../components/SampleDescription';
|
|
30
|
+
|
|
31
|
+
import type { KoliBriTableHeaders } from '@public-ui/components';
|
|
32
|
+
import type { FC } from 'react';
|
|
33
|
+
|
|
34
|
+
export const LabelLang: FC = () => {
|
|
35
|
+
const defaultLabel = (component: string) => [{ text: component }, { text: 'partly english', lang: 'en' }, { text: ' Label', lang: 'de' }];
|
|
36
|
+
|
|
37
|
+
const navLinks = [
|
|
38
|
+
{
|
|
39
|
+
_label: defaultLabel('Link '),
|
|
40
|
+
_href: '#/',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
_label: defaultLabel('Link '),
|
|
44
|
+
_href: '#/',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const tabs = [
|
|
49
|
+
{
|
|
50
|
+
_label: defaultLabel('Tab '),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
_label: 'Second Tab',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const HEADER: KoliBriTableHeaders = {
|
|
58
|
+
horizontal: [[{ label: 'ID', key: 'id', width: 160 }]],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<SampleDescription>
|
|
64
|
+
<p>Label can use additional language attributes for screenreaders.</p>
|
|
65
|
+
</SampleDescription>
|
|
66
|
+
|
|
67
|
+
<div className="grid gap-4">
|
|
68
|
+
<SampleBlock id="label-lang-accordion">
|
|
69
|
+
<KolAccordion _label={defaultLabel('Accordion ')}>
|
|
70
|
+
<p>Contents Accordion</p>
|
|
71
|
+
</KolAccordion>
|
|
72
|
+
</SampleBlock>
|
|
73
|
+
<SampleBlock id="label-lang-alert">
|
|
74
|
+
<KolAlert _label={defaultLabel('Alert ')}>This is the text of the alert.</KolAlert>
|
|
75
|
+
</SampleBlock>
|
|
76
|
+
<SampleBlock id="label-lang-badge">
|
|
77
|
+
<KolBadge _label={defaultLabel('Badge ')}></KolBadge>
|
|
78
|
+
</SampleBlock>
|
|
79
|
+
<SampleBlock id="label-lang-breadcrumb">
|
|
80
|
+
<KolBreadcrumb _label="Breadcrumb" _links={navLinks} />
|
|
81
|
+
</SampleBlock>
|
|
82
|
+
<SampleBlock id="label-lang-button">
|
|
83
|
+
<KolButton _label={defaultLabel('Button ')} />
|
|
84
|
+
</SampleBlock>
|
|
85
|
+
<SampleBlock id="label-lang-button-link">
|
|
86
|
+
<KolButtonLink _label={defaultLabel('ButtonLink ')} />
|
|
87
|
+
</SampleBlock>
|
|
88
|
+
<SampleBlock id="label-lang-card">
|
|
89
|
+
<KolCard _label={defaultLabel('Card ')}>Inhaltsbereich</KolCard>
|
|
90
|
+
</SampleBlock>
|
|
91
|
+
<SampleBlock id="label-lang-details">
|
|
92
|
+
<KolDetails _label={defaultLabel('Details ')}>
|
|
93
|
+
<p>Contents Details</p>
|
|
94
|
+
</KolDetails>
|
|
95
|
+
</SampleBlock>
|
|
96
|
+
<SampleBlock id="label-lang-heading">
|
|
97
|
+
<KolHeading _label={defaultLabel('Heading ')} _level={1} />
|
|
98
|
+
</SampleBlock>
|
|
99
|
+
<SampleBlock id="label-lang-checkbox">
|
|
100
|
+
<KolInputCheckbox _label={defaultLabel('Checkbox')} />
|
|
101
|
+
</SampleBlock>
|
|
102
|
+
<SampleBlock id="label-lang-input">
|
|
103
|
+
<KolInputText _label={defaultLabel('Input ')} />
|
|
104
|
+
</SampleBlock>
|
|
105
|
+
<SampleBlock id="label-lang-link">
|
|
106
|
+
<KolLink _label={defaultLabel('Link ')} _href="" />
|
|
107
|
+
</SampleBlock>
|
|
108
|
+
<SampleBlock id="label-lang-link-button">
|
|
109
|
+
<KolLinkButton _label={defaultLabel('LinkButton ')} _href="" />
|
|
110
|
+
</SampleBlock>
|
|
111
|
+
<SampleBlock id="label-lang-meter">
|
|
112
|
+
<KolMeter _label={defaultLabel('Meter ')} _max={1024} _min={0} _unit="MB" _value={512} />
|
|
113
|
+
</SampleBlock>
|
|
114
|
+
<SampleBlock id="label-lang-nav">
|
|
115
|
+
<KolNav _label="Navi" _links={navLinks} />
|
|
116
|
+
</SampleBlock>
|
|
117
|
+
<SampleBlock id="label-lang-popover">
|
|
118
|
+
<KolPopoverButton _label={defaultLabel('Popover ')}>Text</KolPopoverButton>
|
|
119
|
+
</SampleBlock>
|
|
120
|
+
<SampleBlock id="label-lang-progress">
|
|
121
|
+
<KolProgress _label={defaultLabel('Progress ')} _max={100} _value={45} _variant="bar" />
|
|
122
|
+
</SampleBlock>
|
|
123
|
+
<SampleBlock id="label-lang-quote">
|
|
124
|
+
<KolQuote _href="https://public-ui.github.io/docs" _label={defaultLabel('Quote ')} _quote="Quote." _variant="inline" />
|
|
125
|
+
</SampleBlock>
|
|
126
|
+
<SampleBlock id="label-lang-table">
|
|
127
|
+
<KolTableStateful _label={defaultLabel('Table ')} _data={[]} _headers={HEADER}></KolTableStateful>
|
|
128
|
+
</SampleBlock>
|
|
129
|
+
<SampleBlock id="label-lang-tabs">
|
|
130
|
+
<KolTabs _tabs={tabs} _label="Regular tabs"></KolTabs>
|
|
131
|
+
</SampleBlock>
|
|
132
|
+
<SampleBlock id="label-lang-toolbar">
|
|
133
|
+
<KolToolbar
|
|
134
|
+
_label="Toolbar"
|
|
135
|
+
_items={[
|
|
136
|
+
{
|
|
137
|
+
type: 'button',
|
|
138
|
+
_label: defaultLabel('Button '),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: 'link',
|
|
142
|
+
_label: defaultLabel('Link '),
|
|
143
|
+
_href: '#',
|
|
144
|
+
},
|
|
145
|
+
]}
|
|
146
|
+
></KolToolbar>
|
|
147
|
+
</SampleBlock>
|
|
148
|
+
<SampleBlock id="label-lang-tree">
|
|
149
|
+
<KolTree _label="Tree">
|
|
150
|
+
<KolTreeItem _label={defaultLabel('TreeItem ')} _href="#/" />
|
|
151
|
+
</KolTree>
|
|
152
|
+
</SampleBlock>
|
|
153
|
+
</div>
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
};
|
package/src/scenarios/routes.ts
CHANGED
|
@@ -9,12 +9,12 @@ import { FocusElements } from './focus-elements';
|
|
|
9
9
|
import { TableHorizontalScrollAdvanced } from './horizontal-scrollbar-advanced';
|
|
10
10
|
import { InputGroupWithError } from './input-group-with-error';
|
|
11
11
|
import { InputsGetValue } from './inputs-get-value';
|
|
12
|
+
import { LabelLang } from './label-lang';
|
|
12
13
|
import { PerformanceTest } from './performance-test';
|
|
13
14
|
import { RHFBasic } from './react-hook-form/basic';
|
|
14
15
|
import { RHFDisabled } from './react-hook-form/disabled';
|
|
15
16
|
import { SameHeightOfAllFormElements } from './same-height-of-all-form-elements-with-label';
|
|
16
17
|
import { SameHeightOfAllInteractiveElements } from './same-height-of-all-interactive-elements';
|
|
17
|
-
import { SampleFormWithValidation } from './sample-form-with-validation';
|
|
18
18
|
import { Skeleton } from './skeleton';
|
|
19
19
|
import { StaticForm } from './static-form';
|
|
20
20
|
import { ToolbarItemOrder } from './toolbar-item-order';
|
|
@@ -29,6 +29,7 @@ export const SCENARIO_ROUTES: Routes = {
|
|
|
29
29
|
'date-in-form': DateInForm,
|
|
30
30
|
'disabled-interactive-scenario': DisabledInteractiveElements,
|
|
31
31
|
'focus-elements': FocusElements,
|
|
32
|
+
'label-lang': LabelLang,
|
|
32
33
|
'input-group-with-error': InputGroupWithError,
|
|
33
34
|
'inputs-get-value': InputsGetValue,
|
|
34
35
|
'react-hook-form-adapter': RHFBasic,
|
|
@@ -36,7 +37,6 @@ export const SCENARIO_ROUTES: Routes = {
|
|
|
36
37
|
'same-height-of-all-interactive-elements': SameHeightOfAllInteractiveElements,
|
|
37
38
|
'same-height-of-all-form-elements-with-label': SameHeightOfAllFormElements,
|
|
38
39
|
'static-form': StaticForm,
|
|
39
|
-
'sample-form-with-validation': SampleFormWithValidation,
|
|
40
40
|
'table-horizontal-scrollbar-advanced': TableHorizontalScrollAdvanced,
|
|
41
41
|
'toolbar-item-order': ToolbarItemOrder,
|
|
42
42
|
'tooltip-positioning': TooltipPositioning,
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
-
import {
|
|
3
|
-
KolComboboxController,
|
|
4
|
-
KolInputCheckboxController,
|
|
5
|
-
KolInputColorController,
|
|
6
|
-
KolInputDateController,
|
|
7
|
-
KolInputEmailController,
|
|
8
|
-
KolInputNumberController,
|
|
9
|
-
KolInputPasswordController,
|
|
10
|
-
KolInputRadioController,
|
|
11
|
-
KolInputRangeController,
|
|
12
|
-
KolInputTextController,
|
|
13
|
-
KolSelectController,
|
|
14
|
-
KolSingleSelectController,
|
|
15
|
-
KolTextareaController,
|
|
16
|
-
} from '@public-ui/react-hook-form-adapter';
|
|
17
|
-
import { KolAlert, KolButton, KolHeading, KolLink } from '@public-ui/react-v19';
|
|
18
|
-
import React from 'react';
|
|
19
|
-
import type { FieldError } from 'react-hook-form';
|
|
20
|
-
import { useForm } from 'react-hook-form';
|
|
21
|
-
import { z } from 'zod';
|
|
22
|
-
|
|
23
|
-
import { SampleDescription } from '../components/SampleDescription';
|
|
24
|
-
import { useAlert } from '../hooks/useAlert';
|
|
25
|
-
import { COUNTRY_SUGGESTIONS } from '../shares/country';
|
|
26
|
-
|
|
27
|
-
const formSchema = z.object({
|
|
28
|
-
date: z.preprocess(
|
|
29
|
-
(val) => (typeof val === 'string' || val instanceof Date ? new Date(val) : undefined),
|
|
30
|
-
z.date({ message: 'Date is required' }).refine((d) => !isNaN(d.getTime()), { message: 'Invalid date' }),
|
|
31
|
-
),
|
|
32
|
-
|
|
33
|
-
text: z.string({ message: 'Please enter text.' }).min(10, 'Text must be at least 10 characters long.'),
|
|
34
|
-
email: z.string({ message: 'Please enter your email.' }).min(1, 'Please enter your email.').email('Invalid email address.'),
|
|
35
|
-
password: z
|
|
36
|
-
.string({ message: 'Please enter a password.' })
|
|
37
|
-
.min(8, 'Password must be at least 8 characters.')
|
|
38
|
-
.regex(/[A-Z]/, 'Password must include at least one uppercase letter.')
|
|
39
|
-
.regex(/[0-9]/, 'Password must include at least one number.'),
|
|
40
|
-
range: z.number({ message: 'Please select a range.' }).min(30, 'Minimum value is 30.'),
|
|
41
|
-
number: z.number({ message: 'Please enter a number.' }).min(1, 'Minimum is 1.').max(10, 'Maximum is 10.'),
|
|
42
|
-
checkbox: z.boolean().refine((val: boolean) => val === true, {
|
|
43
|
-
message: 'You must accept the terms and conditions.',
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
radio: z.string({ message: 'Please select a gender.' }).min(1, 'Please select a gender.'),
|
|
47
|
-
color: z.string({ message: 'Please select a color.' }).min(1, 'Please select a color.'),
|
|
48
|
-
select: z.string({ message: 'Please select a value.' }).min(1, 'Please select a value.'),
|
|
49
|
-
singleSelect: z.string({ message: 'Please select a single option.' }).min(1, 'Please select a single option.'),
|
|
50
|
-
combobox: z.string({ message: 'Please select a country.' }).min(1, 'Please select a country.'),
|
|
51
|
-
textarea: z.string({ message: 'Please enter a message.' }).min(1, 'Please enter a message.'),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export const SampleFormWithValidation: React.FC = () => {
|
|
55
|
-
const { dummyClickEventHandler } = useAlert();
|
|
56
|
-
const {
|
|
57
|
-
handleSubmit,
|
|
58
|
-
formState: { errors },
|
|
59
|
-
reset,
|
|
60
|
-
control,
|
|
61
|
-
} = useForm({
|
|
62
|
-
mode: 'onBlur',
|
|
63
|
-
reValidateMode: 'onChange',
|
|
64
|
-
resolver: zodResolver(formSchema),
|
|
65
|
-
defaultValues: {
|
|
66
|
-
range: 30,
|
|
67
|
-
number: 5,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const onReset = () => {
|
|
72
|
-
reset(undefined, {
|
|
73
|
-
keepErrors: false,
|
|
74
|
-
keepTouched: false,
|
|
75
|
-
keepDirty: false,
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const allErrors = Object.entries(errors)
|
|
80
|
-
.map(([key, value]) => [key, (value as FieldError).message] as const)
|
|
81
|
-
.filter(([, msg]) => Boolean(msg));
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<section className="w-full max-w-3xl mx-auto p-6">
|
|
85
|
-
<KolHeading _level={2} _label="Sample Form with Validation (Zod)" />
|
|
86
|
-
<SampleDescription>
|
|
87
|
-
<p>
|
|
88
|
-
This example shows validation with <code>react-hook-form</code>, <code>Zod</code>, and an error list.
|
|
89
|
-
</p>
|
|
90
|
-
</SampleDescription>
|
|
91
|
-
|
|
92
|
-
{allErrors.length > 0 && (
|
|
93
|
-
<KolAlert _type="error" _label="Please fix the following:" _alert _variant="card">
|
|
94
|
-
<ul className="list-disc pl-5">
|
|
95
|
-
{allErrors.map(([key, msg], i) => (
|
|
96
|
-
<li key={i}>
|
|
97
|
-
<KolLink
|
|
98
|
-
_label={msg}
|
|
99
|
-
_href={`#field-${key}`}
|
|
100
|
-
_on={{
|
|
101
|
-
onClick: (e: Event) => {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
const input = document.getElementById(`field-${key}`);
|
|
104
|
-
input?.focus();
|
|
105
|
-
},
|
|
106
|
-
}}
|
|
107
|
-
/>
|
|
108
|
-
</li>
|
|
109
|
-
))}
|
|
110
|
-
</ul>
|
|
111
|
-
</KolAlert>
|
|
112
|
-
)}
|
|
113
|
-
|
|
114
|
-
<form onSubmit={handleSubmit(dummyClickEventHandler)} noValidate className="grid gap-4 mt-6">
|
|
115
|
-
<KolInputDateController control={control as any} name="date" _label="Date" />
|
|
116
|
-
<KolInputTextController control={control as any} name="text" _label="Text (≥ 10 chars)" />
|
|
117
|
-
<KolInputEmailController control={control as any} name="email" _label="Email" />
|
|
118
|
-
<KolInputPasswordController control={control as any} name="password" _label="Password" />
|
|
119
|
-
<KolInputRangeController control={control as any} name="range" _label="Range (≥ 30)" _min={0} _max={100} />
|
|
120
|
-
<KolInputNumberController control={control as any} name="number" _label="Number (1 – 10)" />
|
|
121
|
-
<KolInputCheckboxController control={control as any} name="checkbox" _label="Accept terms" />
|
|
122
|
-
<KolInputRadioController
|
|
123
|
-
control={control as any}
|
|
124
|
-
name="radio"
|
|
125
|
-
_label="Gender"
|
|
126
|
-
_options={[
|
|
127
|
-
{ label: 'Female', value: 'f' },
|
|
128
|
-
{ label: 'Male', value: 'm' },
|
|
129
|
-
]}
|
|
130
|
-
/>
|
|
131
|
-
<KolInputColorController control={control as any} name="color" _label="Favorite Color" />
|
|
132
|
-
<KolSelectController
|
|
133
|
-
control={control as any}
|
|
134
|
-
name="select"
|
|
135
|
-
_label="Select"
|
|
136
|
-
_options={[
|
|
137
|
-
{ label: 'Option A', value: 'A' },
|
|
138
|
-
{ label: 'Option B', value: 'B' },
|
|
139
|
-
]}
|
|
140
|
-
/>
|
|
141
|
-
<KolSingleSelectController
|
|
142
|
-
control={control as any}
|
|
143
|
-
name="singleSelect"
|
|
144
|
-
_label="Single Select"
|
|
145
|
-
_options={[
|
|
146
|
-
{ label: 'Option A', value: 'A' },
|
|
147
|
-
{ label: 'Option B', value: 'B' },
|
|
148
|
-
]}
|
|
149
|
-
/>
|
|
150
|
-
<KolComboboxController control={control as any} name="combobox" _label="Country" _suggestions={COUNTRY_SUGGESTIONS} />
|
|
151
|
-
<KolTextareaController control={control as any} name="textarea" _label="Message" _rows={4} />
|
|
152
|
-
|
|
153
|
-
<div className="flex gap-4 mt-4">
|
|
154
|
-
<KolButton _label="Submit" _type="submit" _variant="primary" />
|
|
155
|
-
<KolButton _label="Reset" _type="reset" onClick={onReset} />
|
|
156
|
-
</div>
|
|
157
|
-
</form>
|
|
158
|
-
</section>
|
|
159
|
-
);
|
|
160
|
-
};
|