@public-ui/sample-react 5.0.0-beta.0 → 5.0.0-beta.2
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 +6 -6
- package/src/@shared/demo-input-wc.ts +98 -0
- package/src/components/button/expert-slot.tsx +0 -5
- package/src/components/dialog/with-alert.tsx +7 -1
- package/src/components/drawer/scrolled.tsx +1 -1
- package/src/components/input-text/aria-details.tsx +101 -3
- package/src/components/progress/dynamic.tsx +50 -0
- package/src/components/progress/routes.ts +2 -0
- package/src/components/table/stateless-async-paging.tsx +1 -0
- package/src/components/table/stateless-with-settings-menu.tsx +1 -0
- package/src/components/tabs/align.tsx +4 -4
- package/src/components/tabs/basic.tsx +8 -8
- package/src/components/tabs/behavior.tsx +8 -8
- package/src/components/tabs/create-button.tsx +3 -3
- package/src/components/tabs/icons-only.tsx +4 -4
- package/src/scenarios/label-lang.tsx +156 -0
- package/src/scenarios/performance-test.tsx +2 -5
- package/src/scenarios/routes.ts +2 -4
- package/src/components/button/expert-slot.tooltip.scss +0 -75
- package/src/scenarios/sample-form-with-validation.tsx +0 -160
- package/src/scenarios/skeleton.tsx +0 -199
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": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.2",
|
|
4
4
|
"description": "This app contains samples for the KoliBri/Public UI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "EUPL-1.2",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@hookform/resolvers": "5.9.2",
|
|
13
|
-
"@stencil/core": "4.45.
|
|
13
|
+
"@stencil/core": "4.45.3",
|
|
14
14
|
"@types/node": "26.4.0",
|
|
15
15
|
"@types/papaparse": "5.5.2",
|
|
16
16
|
"papaparse": "5.7.0",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"typescript": "5.9.3",
|
|
21
21
|
"world_countries_lists": "3.3.0",
|
|
22
22
|
"zod": "4.6.7",
|
|
23
|
-
"@public-ui/react-hook-form-adapter": "5.0.0-beta.
|
|
24
|
-
"@public-ui/react-v19": "5.0.0-beta.
|
|
23
|
+
"@public-ui/react-hook-form-adapter": "5.0.0-beta.2",
|
|
24
|
+
"@public-ui/react-v19": "5.0.0-beta.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "19.2.18",
|
|
28
28
|
"@types/react-dom": "19.2.5",
|
|
29
|
-
"adopted-style-sheets": "1.
|
|
29
|
+
"adopted-style-sheets": "1.2.0-rc.3",
|
|
30
30
|
"eslint": "9.39.5",
|
|
31
31
|
"knip": "6.42.1",
|
|
32
32
|
"prettier": "3.9.10",
|
|
@@ -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": "5.0.0-beta.
|
|
40
|
+
"@public-ui/components": "5.0.0-beta.2"
|
|
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
|
+
}
|
|
@@ -5,10 +5,6 @@ import { useAlert } from '../../hooks/useAlert';
|
|
|
5
5
|
import { SampleBlock } from '../SampleBlock';
|
|
6
6
|
import { SampleDescription } from '../SampleDescription';
|
|
7
7
|
|
|
8
|
-
import './expert-slot.tooltip.scss';
|
|
9
|
-
|
|
10
|
-
const KolTooltip = 'kol-tooltip-wc' as unknown as React.FC<{ _label: string }>;
|
|
11
|
-
|
|
12
8
|
export const ButtonExpertSlot: FC = () => {
|
|
13
9
|
const { dummyClickEventHandler } = useAlert();
|
|
14
10
|
|
|
@@ -40,7 +36,6 @@ export const ButtonExpertSlot: FC = () => {
|
|
|
40
36
|
<KolButton _label="" _variant="danger" _on={dummyEventHandler}>
|
|
41
37
|
<KolIcon _icons="kolicon-alert-warning" _label="Delete with custom text" slot="expert" />
|
|
42
38
|
</KolButton>
|
|
43
|
-
<KolTooltip _label="Delete with custom text" />
|
|
44
39
|
</div>
|
|
45
40
|
</SampleBlock>
|
|
46
41
|
|
|
@@ -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 }}>
|
|
@@ -58,7 +58,7 @@ export const DrawerScrolled: FC = () => {
|
|
|
58
58
|
gap: '20px',
|
|
59
59
|
}}
|
|
60
60
|
>
|
|
61
|
-
<p
|
|
61
|
+
<p>Content with proper overflow handling - scrollable within drawer bounds</p>
|
|
62
62
|
<div>
|
|
63
63
|
<h3>Large Content Area (Scrollable)</h3>
|
|
64
64
|
<p>
|
|
@@ -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,50 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KolButton, KolProgress } from '@public-ui/react-v19';
|
|
4
|
+
|
|
5
|
+
import type { FC } from 'react';
|
|
6
|
+
import { SampleBlock } from '../SampleBlock';
|
|
7
|
+
import { SampleDescription } from '../SampleDescription';
|
|
8
|
+
|
|
9
|
+
const MAX = 100;
|
|
10
|
+
const STEP = 5;
|
|
11
|
+
const TICK_MS = 1000;
|
|
12
|
+
|
|
13
|
+
export const ProgressDynamic: FC = () => {
|
|
14
|
+
const [value, setValue] = useState<number>(0);
|
|
15
|
+
const [running, setRunning] = useState<boolean>(true);
|
|
16
|
+
const [mounted, setMounted] = useState<boolean>(true);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!running) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const timer = setInterval(() => setValue((current) => (current >= MAX ? 0 : current + STEP)), TICK_MS);
|
|
23
|
+
return () => clearInterval(timer);
|
|
24
|
+
}, [running]);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<SampleDescription>
|
|
29
|
+
<p>
|
|
30
|
+
The value grows by {STEP} every second and starts again at 0 after {MAX}. Screen readers announce the current value every 5 seconds through the live
|
|
31
|
+
region. Removing and inserting the components again checks that the announcement continues afterwards.
|
|
32
|
+
</p>
|
|
33
|
+
</SampleDescription>
|
|
34
|
+
|
|
35
|
+
<SampleBlock id="progress-dynamic" skipSnapshot>
|
|
36
|
+
<div className="flex gap-4">
|
|
37
|
+
<KolButton _label={running ? 'Pause' : 'Resume'} _on={{ onClick: () => setRunning(!running) }} />
|
|
38
|
+
<KolButton _label={mounted ? 'Remove' : 'Insert'} _on={{ onClick: () => setMounted(!mounted) }} />
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
{mounted && (
|
|
42
|
+
<>
|
|
43
|
+
<KolProgress _label="Upload" _variant="bar" _max={MAX} _value={value} />
|
|
44
|
+
<KolProgress _label="Upload" _variant="cycle" _max={MAX} _value={value} />
|
|
45
|
+
</>
|
|
46
|
+
)}
|
|
47
|
+
</SampleBlock>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Routes } from '../../shares/types';
|
|
2
2
|
import { ProgressBasic } from './basic';
|
|
3
3
|
import { ProgressChanging } from './changing';
|
|
4
|
+
import { ProgressDynamic } from './dynamic';
|
|
4
5
|
|
|
5
6
|
export const PROGRESS_ROUTES: Routes = {
|
|
6
7
|
progress: {
|
|
7
8
|
basic: ProgressBasic,
|
|
8
9
|
changing: ProgressChanging,
|
|
10
|
+
dynamic: ProgressDynamic,
|
|
9
11
|
},
|
|
10
12
|
};
|
|
@@ -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
|
</>
|
|
@@ -44,10 +44,10 @@ export const TabsAlign: FC = () => (
|
|
|
44
44
|
<div key={align} className="grid gap-4">
|
|
45
45
|
<KolHeading _level={2} _label={text} />
|
|
46
46
|
<KolTabs _tabs={tabs} _align={align} _label={text}>
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
<
|
|
50
|
-
<
|
|
47
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
48
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
49
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
50
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
51
51
|
</KolTabs>
|
|
52
52
|
</div>
|
|
53
53
|
);
|
|
@@ -43,19 +43,19 @@ export const TabsBasic: FC = () => (
|
|
|
43
43
|
|
|
44
44
|
<SampleBlock id="regular">
|
|
45
45
|
<KolTabs _tabs={tabsWithoutIcons} _label="Regular tabs">
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
<
|
|
46
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
47
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
48
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
49
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
50
50
|
</KolTabs>
|
|
51
51
|
</SampleBlock>
|
|
52
52
|
|
|
53
53
|
<SampleBlock id="icons">
|
|
54
54
|
<KolTabs _tabs={tabs} className="mt-4" _label="Tabs with icons">
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
<
|
|
55
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
56
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
57
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
58
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
59
59
|
</KolTabs>
|
|
60
60
|
</SampleBlock>
|
|
61
61
|
</>
|
|
@@ -41,19 +41,19 @@ export const TabsBehavior: FC = () => (
|
|
|
41
41
|
<div className="grid gap-4">
|
|
42
42
|
<KolHeading _level={2} _label='Tabs with "select manual" behavior' />
|
|
43
43
|
<KolTabs _tabs={tabs} _behavior="select-manual" _label="Tabs with select manual behavior">
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
<
|
|
44
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
45
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
46
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
47
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
48
48
|
</KolTabs>
|
|
49
49
|
</div>
|
|
50
50
|
<div className="grid gap-4">
|
|
51
51
|
<KolHeading _level={2} _label='Tabs with "select automatic" behavior' />
|
|
52
52
|
<KolTabs _tabs={tabs} className="mt-4" _behavior="select-automatic" _label="Tabs with select automatic behavior">
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
<
|
|
56
|
-
<
|
|
53
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
54
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
55
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
56
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
57
57
|
</KolTabs>
|
|
58
58
|
</div>
|
|
59
59
|
</div>
|
|
@@ -32,12 +32,12 @@ export const CreateButton: FC = () => {
|
|
|
32
32
|
<SampleBlock id="create-button">
|
|
33
33
|
<KolTabs _tabs={tabs} className="mt-4" _label="Tabs with create button" _hasCreateButton _on={{ onCreate: addTab }}>
|
|
34
34
|
{tabs.map((tab, index) => (
|
|
35
|
-
<
|
|
35
|
+
<p key={`tab-${index}`} slot={`tab-${index}`}>
|
|
36
36
|
Contents of {tab._label}
|
|
37
|
-
</
|
|
37
|
+
</p>
|
|
38
38
|
))}
|
|
39
39
|
|
|
40
|
-
<
|
|
40
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
41
41
|
</KolTabs>
|
|
42
42
|
</SampleBlock>
|
|
43
43
|
</>
|
|
@@ -41,10 +41,10 @@ export const TabsIconsOnly: FC = () => (
|
|
|
41
41
|
|
|
42
42
|
<SampleBlock id="icons-only">
|
|
43
43
|
<KolTabs _label="Tabs with icons" _tabs={tabs}>
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
<
|
|
44
|
+
<p slot="tab-0">Contents of Tab 1</p>
|
|
45
|
+
<p slot="tab-1">Contents of Tab 2</p>
|
|
46
|
+
<p slot="tab-2">Contents of Tab 3</p>
|
|
47
|
+
<p slot="tab-3">Contents of Tab 4</p>
|
|
48
48
|
</KolTabs>
|
|
49
49
|
</SampleBlock>
|
|
50
50
|
</>
|
|
@@ -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
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { KolButton, KolInputCheckbox, KolInputNumber, KolInputText
|
|
1
|
+
import { KolButton, KolInputCheckbox, KolInputNumber, KolInputText } from '@public-ui/react-v19';
|
|
2
2
|
import type { FC } from 'react';
|
|
3
3
|
import React, { useState } from 'react';
|
|
4
4
|
import { SampleDescription } from '../components/SampleDescription';
|
|
5
5
|
|
|
6
|
-
type ComponentType = 'text' | 'number' | 'checkbox'
|
|
6
|
+
type ComponentType = 'text' | 'number' | 'checkbox';
|
|
7
7
|
|
|
8
8
|
export const PerformanceTest: FC = () => {
|
|
9
9
|
const [count, setCount] = useState<number>(100);
|
|
@@ -25,8 +25,6 @@ export const PerformanceTest: FC = () => {
|
|
|
25
25
|
return <KolInputNumber key={idx} _label={`NumberInput #${idx}`} />;
|
|
26
26
|
case 'checkbox':
|
|
27
27
|
return <KolInputCheckbox key={idx} _label={`Checkbox #${idx}`} />;
|
|
28
|
-
case 'skeleton':
|
|
29
|
-
return <KolSkeleton key={idx} _name={`skeleton-${idx}`} />;
|
|
30
28
|
default:
|
|
31
29
|
return null;
|
|
32
30
|
}
|
|
@@ -78,7 +76,6 @@ export const PerformanceTest: FC = () => {
|
|
|
78
76
|
<KolButton _label="Render TextInputs" _variant="primary" onClick={() => handleComponentRender('text')} />
|
|
79
77
|
<KolButton _label="Render NumberInputs" _variant="primary" onClick={() => handleComponentRender('number')} />
|
|
80
78
|
<KolButton _label="Render Checkboxes" _variant="primary" onClick={() => handleComponentRender('checkbox')} />
|
|
81
|
-
<KolButton _label="Render Skeletons" _variant="primary" onClick={() => handleComponentRender('skeleton')} />
|
|
82
79
|
<KolButton _label="Clear" _variant="secondary" onClick={handleClear} />
|
|
83
80
|
</div>
|
|
84
81
|
</div>
|
package/src/scenarios/routes.ts
CHANGED
|
@@ -9,13 +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
|
-
import { Skeleton } from './skeleton';
|
|
19
18
|
import { StaticForm } from './static-form';
|
|
20
19
|
import { ToolbarItemOrder } from './toolbar-item-order';
|
|
21
20
|
import { TooltipPositioning } from './tooltip-positioning';
|
|
@@ -29,6 +28,7 @@ export const SCENARIO_ROUTES: Routes = {
|
|
|
29
28
|
'date-in-form': DateInForm,
|
|
30
29
|
'disabled-interactive-scenario': DisabledInteractiveElements,
|
|
31
30
|
'focus-elements': FocusElements,
|
|
31
|
+
'label-lang': LabelLang,
|
|
32
32
|
'input-group-with-error': InputGroupWithError,
|
|
33
33
|
'inputs-get-value': InputsGetValue,
|
|
34
34
|
'react-hook-form-adapter': RHFBasic,
|
|
@@ -36,13 +36,11 @@ export const SCENARIO_ROUTES: Routes = {
|
|
|
36
36
|
'same-height-of-all-interactive-elements': SameHeightOfAllInteractiveElements,
|
|
37
37
|
'same-height-of-all-form-elements-with-label': SameHeightOfAllFormElements,
|
|
38
38
|
'static-form': StaticForm,
|
|
39
|
-
'sample-form-with-validation': SampleFormWithValidation,
|
|
40
39
|
'table-horizontal-scrollbar-advanced': TableHorizontalScrollAdvanced,
|
|
41
40
|
'toolbar-item-order': ToolbarItemOrder,
|
|
42
41
|
'tooltip-positioning': TooltipPositioning,
|
|
43
42
|
'accordion-components': AccordionComponentContent,
|
|
44
43
|
'z-index': ZIndexScenario,
|
|
45
44
|
'performance-test': PerformanceTest,
|
|
46
|
-
skeleton: Skeleton,
|
|
47
45
|
},
|
|
48
46
|
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// kol-tooltip-wc uses shadow: false — its styles live in the light DOM.
|
|
2
|
-
// These base styles mirror packages/components/src/components/tooltip/style.scss
|
|
3
|
-
// and are required when the component is used without a fully bootstrapped theme.
|
|
4
|
-
.kol-tooltip {
|
|
5
|
-
display: contents;
|
|
6
|
-
|
|
7
|
-
&__floating {
|
|
8
|
-
opacity: 0;
|
|
9
|
-
display: none;
|
|
10
|
-
position: fixed;
|
|
11
|
-
top: 0;
|
|
12
|
-
left: 0;
|
|
13
|
-
width: max-content;
|
|
14
|
-
max-width: 90vw;
|
|
15
|
-
max-height: 90vh;
|
|
16
|
-
animation-direction: normal;
|
|
17
|
-
animation-duration: 250ms;
|
|
18
|
-
animation-fill-mode: forwards;
|
|
19
|
-
animation-iteration-count: 1;
|
|
20
|
-
animation-timing-function: ease-in;
|
|
21
|
-
|
|
22
|
-
&.hide {
|
|
23
|
-
animation-name: hideTooltip;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&.show {
|
|
27
|
-
animation-name: showTooltip;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&__arrow {
|
|
32
|
-
transform: rotate(45deg);
|
|
33
|
-
background-color: #fff;
|
|
34
|
-
|
|
35
|
-
position: absolute;
|
|
36
|
-
z-index: 999;
|
|
37
|
-
width: 10px;
|
|
38
|
-
height: 10px;
|
|
39
|
-
|
|
40
|
-
border: 1px solid #ccc;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
&__content {
|
|
44
|
-
color: #000;
|
|
45
|
-
background-color: #fff;
|
|
46
|
-
border-radius: 4px;
|
|
47
|
-
|
|
48
|
-
position: relative;
|
|
49
|
-
z-index: 1000;
|
|
50
|
-
padding: 4px 12px;
|
|
51
|
-
|
|
52
|
-
border: 1px solid #ccc;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@keyframes hideTooltip {
|
|
57
|
-
0% {
|
|
58
|
-
opacity: 1;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
100% {
|
|
62
|
-
opacity: 0;
|
|
63
|
-
display: none;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@keyframes showTooltip {
|
|
68
|
-
0% {
|
|
69
|
-
opacity: 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
100% {
|
|
73
|
-
opacity: 1;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -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
|
-
};
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
import React, { useCallback, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { KolButton, KolInputRange, KolSkeleton } from '@public-ui/react-v19';
|
|
5
|
-
import { SampleDescription } from '../components/SampleDescription';
|
|
6
|
-
|
|
7
|
-
interface EventLogEntry {
|
|
8
|
-
timestamp: string;
|
|
9
|
-
count: number;
|
|
10
|
-
id: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Skeleton: FC = () => {
|
|
14
|
-
const skeletonRef = useRef<HTMLKolSkeletonElement>(null);
|
|
15
|
-
const rangeRef = useRef<HTMLKolInputRangeElement>(null);
|
|
16
|
-
const initialCount = 3;
|
|
17
|
-
|
|
18
|
-
const durationFormatter = new Intl.NumberFormat('de-DE', { style: 'unit', unit: 'millisecond', maximumFractionDigits: 1 });
|
|
19
|
-
const timeFormatter = new Intl.DateTimeFormat('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
20
|
-
|
|
21
|
-
const [count, setCount] = useState<number>(initialCount);
|
|
22
|
-
const [eventLog, setEventLog] = useState<EventLogEntry[]>([]);
|
|
23
|
-
const [lastEventTime, setLastEventTime] = useState<string>('');
|
|
24
|
-
const [eventCount, setEventCount] = useState<number>(0);
|
|
25
|
-
const [skeletonCount, setSkeletonCount] = useState<number>(20);
|
|
26
|
-
|
|
27
|
-
// Render benchmark state
|
|
28
|
-
const [generation, setGeneration] = useState<number>(0);
|
|
29
|
-
const [renderDuration, setRenderDuration] = useState<number | null>(null);
|
|
30
|
-
const [isMeasuring, setIsMeasuring] = useState<boolean>(false);
|
|
31
|
-
|
|
32
|
-
// Refs for stable values in closures (no stale closure issues)
|
|
33
|
-
const renderStartTimeRef = useRef<number>(0);
|
|
34
|
-
const expectedCountRef = useRef<number>(20);
|
|
35
|
-
const renderedCountRef = useRef<number>(0);
|
|
36
|
-
|
|
37
|
-
const handleLoaded = (event: CustomEvent<number>) => {
|
|
38
|
-
const now = new Date();
|
|
39
|
-
const timestamp = timeFormatter.format(now);
|
|
40
|
-
const newEventCount = eventCount + 1;
|
|
41
|
-
|
|
42
|
-
setCount(event.detail);
|
|
43
|
-
setLastEventTime(timestamp);
|
|
44
|
-
setEventCount(newEventCount);
|
|
45
|
-
|
|
46
|
-
// Add to event log (keep only last 5 entries)
|
|
47
|
-
setEventLog((prev) => {
|
|
48
|
-
const newEntry: EventLogEntry = {
|
|
49
|
-
timestamp,
|
|
50
|
-
count: event.detail,
|
|
51
|
-
id: newEventCount,
|
|
52
|
-
};
|
|
53
|
-
return [newEntry, ...prev.slice(0, 4)];
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleRendered = useCallback(() => {
|
|
58
|
-
renderedCountRef.current += 1;
|
|
59
|
-
|
|
60
|
-
if (renderedCountRef.current >= expectedCountRef.current) {
|
|
61
|
-
const duration = performance.now() - renderStartTimeRef.current;
|
|
62
|
-
setRenderDuration(duration);
|
|
63
|
-
setIsMeasuring(false);
|
|
64
|
-
}
|
|
65
|
-
}, []);
|
|
66
|
-
|
|
67
|
-
const handleRangeChange = (_event: Event, value: unknown) => {
|
|
68
|
-
const newValue = Number(value);
|
|
69
|
-
setSkeletonCount(newValue);
|
|
70
|
-
|
|
71
|
-
// Start benchmark measurement
|
|
72
|
-
renderedCountRef.current = 0;
|
|
73
|
-
expectedCountRef.current = newValue;
|
|
74
|
-
renderStartTimeRef.current = performance.now();
|
|
75
|
-
setRenderDuration(null);
|
|
76
|
-
setIsMeasuring(true);
|
|
77
|
-
setGeneration((prev) => prev + 1);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const handleRangeBlur = () => {
|
|
81
|
-
// Sicherstellen, dass der interne Wert mit dem State synchronisiert ist
|
|
82
|
-
if (rangeRef.current) {
|
|
83
|
-
rangeRef.current._value = skeletonCount;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<>
|
|
89
|
-
<SampleDescription>
|
|
90
|
-
<p>
|
|
91
|
-
KolSkeleton demonstriert Event-Emitter mit automatischem Intervall. Die Komponente emittiert alle 2 Sekunden ein "loaded" Event mit dem
|
|
92
|
-
aktuellen Count-Wert. Über die Buttons kann die Komponente getoggled und fokussiert werden. Der interne ClickButton erhöht bei Klick den Counter.
|
|
93
|
-
</p>
|
|
94
|
-
</SampleDescription>
|
|
95
|
-
|
|
96
|
-
<div className="grid md:grid-cols-2 gap-4 mb-4 items-center">
|
|
97
|
-
<div className="grid sm:grid-cols-2 gap-4">
|
|
98
|
-
<KolButton
|
|
99
|
-
_label="Toggle Sichtbarkeit"
|
|
100
|
-
_on={{
|
|
101
|
-
onClick: () => skeletonRef.current?.toggle(),
|
|
102
|
-
}}
|
|
103
|
-
_variant="primary"
|
|
104
|
-
/>
|
|
105
|
-
<KolButton
|
|
106
|
-
_label="Fokus auf Button"
|
|
107
|
-
_on={{
|
|
108
|
-
onClick: () => skeletonRef.current?.focus(),
|
|
109
|
-
}}
|
|
110
|
-
_variant="secondary"
|
|
111
|
-
/>
|
|
112
|
-
</div>
|
|
113
|
-
<div className="grid sm:grid-cols-2 gap-4 items-center">
|
|
114
|
-
<KolInputRange
|
|
115
|
-
ref={rangeRef}
|
|
116
|
-
_label="Anzahl der Skeletons"
|
|
117
|
-
_hideLabel
|
|
118
|
-
_min={1}
|
|
119
|
-
_max={10000}
|
|
120
|
-
_step={25}
|
|
121
|
-
_value={skeletonCount}
|
|
122
|
-
_on={{
|
|
123
|
-
onChange: handleRangeChange,
|
|
124
|
-
onBlur: handleRangeBlur,
|
|
125
|
-
}}
|
|
126
|
-
/>
|
|
127
|
-
<span className="text-sm text-gray-600 whitespace-nowrap">{skeletonCount} Skeletons</span>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
|
|
131
|
-
{/* Render Benchmark */}
|
|
132
|
-
<div className="mb-4 px-3 py-2 border border-gray-300 rounded bg-gray-50 flex items-center gap-4 text-sm">
|
|
133
|
-
<span className="font-semibold">Benchmark:</span>
|
|
134
|
-
<span className={isMeasuring ? 'text-orange-600 font-bold' : renderDuration !== null ? 'text-green-600' : 'text-gray-400'}>
|
|
135
|
-
{isMeasuring ? 'Rendering…' : renderDuration !== null ? 'Fertig' : 'Bereit'}
|
|
136
|
-
</span>
|
|
137
|
-
<span className="font-bold text-blue-600" aria-live="polite">
|
|
138
|
-
{renderDuration !== null ? durationFormatter.format(renderDuration) : '—'}
|
|
139
|
-
</span>
|
|
140
|
-
</div>
|
|
141
|
-
|
|
142
|
-
<div className="flex flex-wrap gap-4">
|
|
143
|
-
{Array.from({ length: skeletonCount }, (_, idx) => (
|
|
144
|
-
<KolSkeleton
|
|
145
|
-
key={`skeleton-${generation}-${idx}`}
|
|
146
|
-
_name={`Example ${idx}`}
|
|
147
|
-
onLoaded={idx === 0 ? handleLoaded : undefined}
|
|
148
|
-
onRendered={handleRendered}
|
|
149
|
-
ref={idx === 0 ? skeletonRef : undefined}
|
|
150
|
-
/>
|
|
151
|
-
))}
|
|
152
|
-
</div>
|
|
153
|
-
|
|
154
|
-
<div className="mt-6 p-4 border border-gray-300 rounded-lg bg-gray-50">
|
|
155
|
-
<h3 className="text-lg font-semibold mb-3">Event Monitor</h3>
|
|
156
|
-
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
157
|
-
<div>
|
|
158
|
-
<p className="font-medium">Aktueller Count-Wert:</p>
|
|
159
|
-
<p className="text-2xl font-bold text-blue-600" aria-live="polite">
|
|
160
|
-
{count}
|
|
161
|
-
</p>
|
|
162
|
-
</div>
|
|
163
|
-
<div>
|
|
164
|
-
<p className="font-medium">Letztes Event:</p>
|
|
165
|
-
<p className="text-lg" aria-live="polite">
|
|
166
|
-
{lastEventTime || 'Noch kein Event empfangen'}
|
|
167
|
-
</p>
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
170
|
-
<div className="mt-4">
|
|
171
|
-
<p className="font-medium mb-2">
|
|
172
|
-
Events empfangen: <span className="font-bold">{eventCount}</span>
|
|
173
|
-
</p>
|
|
174
|
-
{eventLog.length > 0 && (
|
|
175
|
-
<div>
|
|
176
|
-
<p className="font-medium mb-2">Event-Historie (letzte 5):</p>
|
|
177
|
-
<ul className="text-sm space-y-1 max-h-32 overflow-y-auto">
|
|
178
|
-
{eventLog.map((entry) => (
|
|
179
|
-
<li key={entry.id} className="flex justify-between items-center p-2 bg-white rounded border">
|
|
180
|
-
<span>
|
|
181
|
-
#{entry.id}: Count = {entry.count}
|
|
182
|
-
</span>
|
|
183
|
-
<span className="text-gray-500">{entry.timestamp}</span>
|
|
184
|
-
</li>
|
|
185
|
-
))}
|
|
186
|
-
</ul>
|
|
187
|
-
</div>
|
|
188
|
-
)}
|
|
189
|
-
</div>
|
|
190
|
-
<div className="mt-4 p-3 bg-blue-50 rounded">
|
|
191
|
-
<p className="text-sm text-blue-800">
|
|
192
|
-
💡 <strong>Tipp:</strong> Die Komponente emittiert automatisch alle 2 Sekunden ein Event. Klicke auf den "Click Button" in der Komponente,
|
|
193
|
-
um den Count-Wert zu erhöhen.
|
|
194
|
-
</p>
|
|
195
|
-
</div>
|
|
196
|
-
</div>
|
|
197
|
-
</>
|
|
198
|
-
);
|
|
199
|
-
};
|