@public-ui/sample-react 5.0.0-beta.2 → 5.0.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@public-ui/sample-react",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.4",
4
4
  "description": "This app contains samples for the KoliBri/Public UI",
5
5
  "type": "module",
6
6
  "license": "EUPL-1.2",
@@ -20,8 +20,8 @@
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.2",
24
- "@public-ui/react-v19": "5.0.0-beta.2"
23
+ "@public-ui/react-hook-form-adapter": "5.0.0-beta.4",
24
+ "@public-ui/react-v19": "5.0.0-beta.4"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "19.2.18",
@@ -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.2"
40
+ "@public-ui/components": "5.0.0-beta.4"
41
41
  },
42
42
  "files": [
43
43
  "assets",
@@ -0,0 +1,16 @@
1
+ import type { FC } from 'react';
2
+ import React from 'react';
3
+
4
+ import { FormWrap } from '../FormWrap';
5
+ import { SampleDescription } from '../SampleDescription';
6
+ import { InputFileVariantsDragnDrop } from './partials/variants';
7
+
8
+ export const InputFileDragnDrop: FC = () => (
9
+ <>
10
+ <SampleDescription>
11
+ <p>KolInputFile renders a file input field. The sample shows KolInputFile in a form context with all variations and states.</p>
12
+ </SampleDescription>
13
+
14
+ <FormWrap RefComponent={InputFileVariantsDragnDrop} showButtons={false} />
15
+ </>
16
+ );
@@ -84,3 +84,23 @@ export const InputFileCases = forwardRef<HTMLKolInputFileElement, InputFileCases
84
84
  </div>
85
85
  );
86
86
  });
87
+
88
+ export const InputFileCasesDragnDrop = forwardRef<HTMLKolInputFileElement, InputFileCasesProps>(function InputFileCases({ blockIdPrefix, ...props }) {
89
+ const block = (caseId: string) => ({ id: `${blockIdPrefix}-${caseId}` });
90
+ return (
91
+ <div className="grid gap-4">
92
+ <SampleBlock {...block('accept')}>
93
+ <KolInputFile {...props} _label="Accept" _touched />
94
+ </SampleBlock>
95
+ <SampleBlock {...block('accept-multiple')}>
96
+ <KolInputFile {...props} _label="Accept multiple" _multiple _touched />
97
+ </SampleBlock>
98
+ <SampleBlock {...block('accept-disabled')}>
99
+ <KolInputFile {...props} _label="Accept disabled" _disabled _touched />
100
+ </SampleBlock>
101
+ <SampleBlock {...block('accept-multiple-disabled')}>
102
+ <KolInputFile {...props} _label="Accept multiple disabled" _multiple _disabled _touched />
103
+ </SampleBlock>
104
+ </div>
105
+ );
106
+ });
@@ -2,7 +2,7 @@ import React, { forwardRef } from 'react';
2
2
 
3
3
  import { SampleColumns } from '../../SampleColumns';
4
4
  import { SampleGroup } from '../../SampleGroup';
5
- import { InputFileCases } from './cases';
5
+ import { InputFileCases, InputFileCasesDragnDrop } from './cases';
6
6
 
7
7
  import type { Components } from '@public-ui/components';
8
8
  export const InputFileVariants = forwardRef<HTMLKolInputFileElement, Components.KolInputFile>(function InputFileVariant(props, ref) {
@@ -17,3 +17,16 @@ export const InputFileVariants = forwardRef<HTMLKolInputFileElement, Components.
17
17
  </SampleColumns>
18
18
  );
19
19
  });
20
+
21
+ export const InputFileVariantsDragnDrop = forwardRef<HTMLKolInputFileElement, Components.KolInputFile>(function InputFileVariant(props) {
22
+ return (
23
+ <SampleColumns>
24
+ <SampleGroup heading="File">
25
+ <InputFileCasesDragnDrop blockIdPrefix="label" {...props} _accept=".pdf" />
26
+ </SampleGroup>
27
+ <SampleGroup heading="File (hideLabel)">
28
+ <InputFileCasesDragnDrop blockIdPrefix="hide-label" {...props} _accept=".pdf" _hideLabel />
29
+ </SampleGroup>
30
+ </SampleColumns>
31
+ );
32
+ });
@@ -1,10 +1,14 @@
1
1
  import type { Routes } from '../../shares/types';
2
2
  import { InputFileBasic } from './basic';
3
+ import { InputFileDragnDrop } from './drag-and-drop';
3
4
  import { InputFileOnInputOnChange } from './get-value';
5
+ import { InputFileWithFile } from './with-file';
4
6
 
5
7
  export const INPUT_FILE_ROUTES: Routes = {
6
8
  'input-file': {
7
9
  basic: InputFileBasic,
10
+ 'drag-and-drop': InputFileDragnDrop,
8
11
  'get-value': InputFileOnInputOnChange,
12
+ 'with-file': InputFileWithFile,
9
13
  },
10
14
  };
@@ -0,0 +1,55 @@
1
+ import { KolInputFile } from '@public-ui/react-v19';
2
+ import type { FC } from 'react';
3
+ import React, { useEffect, useRef } from 'react';
4
+
5
+ import { SampleBlock } from '../SampleBlock';
6
+ import { SampleDescription } from '../SampleDescription';
7
+
8
+ const FIRST_FILE_NAME = 'rechnung-antragsunterlagen-einkommensnachweis-mit-einem-absichtlich-sehr-langen-dateinamen.pdf';
9
+ const SECOND_FILE_NAME = 'anlage-vermoegensaufstellung-2026-mit-den-ebenen-aller-gesellschafter-und-beteiligungen.pdf';
10
+
11
+ /**
12
+ * There is no public API to preselect files, so the sample sets them on the native input inside
13
+ * the shadow root and dispatches `change`, like a selection in the file dialog would. The retry
14
+ * bridges the frames until the custom element has rendered its shadow content.
15
+ */
16
+ function usePreselectedFiles(ref: React.RefObject<HTMLKolInputFileElement | null>, fileNames: string[]): void {
17
+ useEffect(() => {
18
+ let frames = 0;
19
+ const tick = () => {
20
+ const input = ref.current?.shadowRoot?.querySelector<HTMLInputElement>('input.kol-input');
21
+ if (input) {
22
+ const transfer = new DataTransfer();
23
+ for (const name of fileNames) {
24
+ transfer.items.add(new File(['preselected for the snapshot'], name, { type: 'application/pdf' }));
25
+ }
26
+ input.files = transfer.files;
27
+ input.dispatchEvent(new Event('change', { bubbles: true }));
28
+ } else if (++frames < 30) {
29
+ requestAnimationFrame(tick);
30
+ }
31
+ };
32
+ requestAnimationFrame(tick);
33
+ }, [fileNames, ref]);
34
+ }
35
+
36
+ export const InputFileWithFile: FC = () => {
37
+ const singleRef = useRef<HTMLKolInputFileElement>(null);
38
+ const multipleRef = useRef<HTMLKolInputFileElement>(null);
39
+ usePreselectedFiles(singleRef, [FIRST_FILE_NAME]);
40
+ usePreselectedFiles(multipleRef, [FIRST_FILE_NAME, SECOND_FILE_NAME]);
41
+
42
+ return (
43
+ <>
44
+ <SampleDescription>
45
+ <p>Preselects files with very long names, so the snapshots pin the wrapping of the file name and the browse button growing with the field.</p>
46
+ </SampleDescription>
47
+ <SampleBlock id="long-name" narrow>
48
+ <KolInputFile ref={singleRef} _label="Upload file" />
49
+ </SampleBlock>
50
+ <SampleBlock id="long-names-multiple" narrow>
51
+ <KolInputFile ref={multipleRef} _label="Upload files" _multiple />
52
+ </SampleBlock>
53
+ </>
54
+ );
55
+ };
@@ -2,7 +2,6 @@ import type { Routes } from '../shares/types';
2
2
  import { AccordionComponentContent } from './accordionComponentContent';
3
3
  import { ButtonShortkeyTable } from './button-shortkey-table';
4
4
  import { ChangeTabindex } from './change-tabindex';
5
- import { CustomTooltipCssProperties } from './custom-tooltip-css-properties';
6
5
  import { DateInForm } from './date-in-form';
7
6
  import { DisabledInteractiveElements } from './disabled-interactive-elements';
8
7
  import { FocusElements } from './focus-elements';
@@ -24,7 +23,6 @@ export const SCENARIO_ROUTES: Routes = {
24
23
  scenarios: {
25
24
  'button-shortkey-table': ButtonShortkeyTable,
26
25
  'change-tabindex': ChangeTabindex,
27
- 'custom-tooltip-css-properties': CustomTooltipCssProperties,
28
26
  'date-in-form': DateInForm,
29
27
  'disabled-interactive-scenario': DisabledInteractiveElements,
30
28
  'focus-elements': FocusElements,
@@ -1,36 +0,0 @@
1
- import type { FC } from 'react';
2
- import React from 'react';
3
-
4
- import { KolButton } from '@public-ui/react-v19';
5
- import { SampleDescription } from '../components/SampleDescription';
6
- import { useAlert } from '../hooks/useAlert';
7
-
8
- export const CustomTooltipCssProperties: FC = () => {
9
- const { dummyClickEventHandler } = useAlert();
10
-
11
- const dummyEventHandler = {
12
- onClick: dummyClickEventHandler,
13
- };
14
-
15
- return (
16
- <>
17
- <SampleDescription>
18
- <p>
19
- This sample demonstrates how tooltip animation duration and width can be customized via
20
- <code>--kolibri-tooltip-animation-duration</code> and <code>--kol-tooltip-width</code>.
21
- </p>
22
- </SampleDescription>
23
-
24
- <div className="flex justify-center items-center gap-4">
25
- <KolButton
26
- _label="Custom duration"
27
- _hideLabel
28
- style={{ '--kolibri-tooltip-animation-duration': '2500ms' }}
29
- _icons="fa-solid fa-clock"
30
- _on={dummyEventHandler}
31
- ></KolButton>
32
- <KolButton _label="Custom width" _hideLabel style={{ '--kol-tooltip-width': '400px' }} _icons="kolicon-chevron-up" _on={dummyEventHandler}></KolButton>
33
- </div>
34
- </>
35
- );
36
- };