@public-ui/sample-react 1.7.0-rc.8 → 1.7.0-rc.9
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 +4 -4
- package/src/App.tsx +1 -1
- package/src/components/Sidebar.tsx +35 -21
- package/src/components/input-password/basic.tsx +2 -15
- package/src/components/input-password/routes.ts +2 -0
- package/src/components/input-password/show-password.tsx +38 -0
- package/src/hooks/useMobile.ts +21 -0
- package/src/style.scss +12 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@public-ui/sample-react",
|
|
3
|
-
"version": "1.7.0-rc.
|
|
3
|
+
"version": "1.7.0-rc.9",
|
|
4
4
|
"description": "This app contains samples for the KoliBri/Public UI",
|
|
5
5
|
"license": "EUPL-1.2",
|
|
6
6
|
"scripts": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@leanup/stack-react": "1.3.48",
|
|
25
25
|
"@leanup/stack-webpack": "1.3.48",
|
|
26
26
|
"@public-oss/kolibri-themes": "0.0.3",
|
|
27
|
-
"@public-ui/components": "1.7.0-rc.
|
|
28
|
-
"@public-ui/react": "1.7.0-rc.
|
|
29
|
-
"@public-ui/themes": "1.7.0-rc.
|
|
27
|
+
"@public-ui/components": "1.7.0-rc.9",
|
|
28
|
+
"@public-ui/react": "1.7.0-rc.9",
|
|
29
|
+
"@public-ui/themes": "1.7.0-rc.9",
|
|
30
30
|
"@types/react": "18.2.21",
|
|
31
31
|
"@types/react-dom": "18.2.7",
|
|
32
32
|
"@unocss/preset-uno": "0.55.7",
|
package/src/App.tsx
CHANGED
|
@@ -120,7 +120,7 @@ export const App: FC = () => {
|
|
|
120
120
|
/>
|
|
121
121
|
)}
|
|
122
122
|
|
|
123
|
-
<div className="p-4">
|
|
123
|
+
<div className="p-4" id="route-container">
|
|
124
124
|
<Routes>
|
|
125
125
|
{ROUTE_TREE}
|
|
126
126
|
<Route path="*" element={<KolAlert _type="info">This code example has not been migrated yet - it's coming soon!</KolAlert>} />
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React, { FC, useState } from 'react';
|
|
2
|
-
import { KolButton, KolHeading, KolLink, KolSelect, KolVersion } from '@public-ui/react';
|
|
1
|
+
import React, { FC, PropsWithChildren, useState } from 'react';
|
|
2
|
+
import { KolAccordion, KolButton, KolHeading, KolLink, KolSelect, KolVersion } from '@public-ui/react';
|
|
3
3
|
import { THEME_OPTIONS } from '../shares/theme';
|
|
4
4
|
import { Routes } from '../shares/types';
|
|
5
|
+
import { useMobile } from '../hooks/useMobile';
|
|
5
6
|
|
|
6
7
|
type Props = {
|
|
7
8
|
version: string;
|
|
@@ -12,9 +13,18 @@ type Props = {
|
|
|
12
13
|
onThemeChange: (theme: unknown) => void;
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
const ComponentNavContainer = ({ children, isMobile }: PropsWithChildren<{ isMobile: boolean }>) =>
|
|
17
|
+
isMobile ? (
|
|
18
|
+
<KolAccordion _label="Alle Komponenten" class="mt">
|
|
19
|
+
{children}
|
|
20
|
+
</KolAccordion>
|
|
21
|
+
) : (
|
|
22
|
+
<div className="mt">{children}</div>
|
|
23
|
+
);
|
|
15
24
|
export const Sidebar: FC<Props> = ({ version, theme, routes, routeList, sample, onThemeChange }) => {
|
|
16
25
|
/* KolSelect calls onChange initially by design - work around this with a state variable */
|
|
17
26
|
const [isFirstThemeSelectChange, setIsFirstThemeSelectChange] = useState(true);
|
|
27
|
+
const isMobile = useMobile();
|
|
18
28
|
|
|
19
29
|
const getIndexOfSample = () => routeList.indexOf(sample);
|
|
20
30
|
const formatSampleAsLabel = () => sample.replace(/\//g, ' ');
|
|
@@ -29,8 +39,7 @@ export const Sidebar: FC<Props> = ({ version, theme, routes, routeList, sample,
|
|
|
29
39
|
|
|
30
40
|
const handleLinkClick = (event: Event) => {
|
|
31
41
|
location.replace((event.target as HTMLLinkElement).href); // KoliBri prevents the default click behavior as soon as an event listener is set, so we need to reimplement it.
|
|
32
|
-
document.
|
|
33
|
-
// @todo set focus?
|
|
42
|
+
document.querySelector('#route-container')?.scrollIntoView({ behavior: 'smooth' });
|
|
34
43
|
};
|
|
35
44
|
|
|
36
45
|
const handlePreviousClick = () => {
|
|
@@ -57,25 +66,30 @@ export const Sidebar: FC<Props> = ({ version, theme, routes, routeList, sample,
|
|
|
57
66
|
<KolHeading _label="Komponenten" _level={2} className="block mt"></KolHeading>
|
|
58
67
|
<div className="flex flex-justify-between flex-items-center mt">
|
|
59
68
|
<KolButton _icon="codicon codicon-arrow-left" _hideLabel _label="Vorherige Komponente auswählen" _on={{ onClick: handlePreviousClick }} />
|
|
60
|
-
|
|
69
|
+
<span className="text-center">
|
|
70
|
+
{formatSampleAsLabel()} ({getIndexOfSample() + 1}/{routeList.length})
|
|
71
|
+
</span>
|
|
61
72
|
<KolButton _icon="codicon codicon-arrow-right" _hideLabel _label="Nächste Komponente auswählen" _on={{ onClick: handleNextClick }} />
|
|
62
73
|
</div>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
|
|
75
|
+
<ComponentNavContainer isMobile={isMobile}>
|
|
76
|
+
<nav>
|
|
77
|
+
<ul className="m0 p0 list-inside">
|
|
78
|
+
{Object.entries(routes).map(([parentName, children]) => (
|
|
79
|
+
<li key={parentName} className="mt-2">
|
|
80
|
+
{parentName}
|
|
81
|
+
<ul className="list-inside ml p0">
|
|
82
|
+
{Object.keys(children).map((childName) => (
|
|
83
|
+
<li key={`${parentName}/${childName}`}>
|
|
84
|
+
<KolLink _label={childName} _href={`#/${parentName}/${childName}`} _on={{ onClick: handleLinkClick }} />
|
|
85
|
+
</li>
|
|
86
|
+
))}
|
|
87
|
+
</ul>
|
|
88
|
+
</li>
|
|
89
|
+
))}
|
|
90
|
+
</ul>
|
|
91
|
+
</nav>
|
|
92
|
+
</ComponentNavContainer>
|
|
79
93
|
</aside>
|
|
80
94
|
);
|
|
81
95
|
};
|
|
@@ -7,8 +7,9 @@ import { ERROR_MSG } from '../../shares/constants';
|
|
|
7
7
|
|
|
8
8
|
export const InputPasswordBasic: FC = () => (
|
|
9
9
|
<KolForm className="grid gap-4">
|
|
10
|
+
<KolInputPassword _disabled _error={ERROR_MSG} _label="Passwort (Disabled)" />
|
|
11
|
+
<KolInputPassword _read-only _label="Passwort (Readonly)" />
|
|
10
12
|
<KolInputPassword
|
|
11
|
-
_id="password"
|
|
12
13
|
_name="password"
|
|
13
14
|
_required
|
|
14
15
|
_error={ERROR_MSG}
|
|
@@ -22,20 +23,6 @@ export const InputPasswordBasic: FC = () => (
|
|
|
22
23
|
icon: 'codicon codicon-arrow-right',
|
|
23
24
|
},
|
|
24
25
|
}}
|
|
25
|
-
_smartButton={{
|
|
26
|
-
_icon: {
|
|
27
|
-
left: {
|
|
28
|
-
icon: 'codicon codicon-eye',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
_hideLabel: true,
|
|
32
|
-
_label: 'Passwort anzeigen',
|
|
33
|
-
_on: {
|
|
34
|
-
onClick: () => {},
|
|
35
|
-
},
|
|
36
|
-
}}
|
|
37
26
|
/>
|
|
38
|
-
<KolInputPassword _disabled _id="password" _error={ERROR_MSG} _label="Passwort (Disabled)" />
|
|
39
|
-
<KolInputPassword _id="password" _read-only _label="Passwort (Readonly)" />
|
|
40
27
|
</KolForm>
|
|
41
28
|
);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Routes } from '../../shares/types';
|
|
2
2
|
|
|
3
3
|
import { InputPasswordBasic } from './basic';
|
|
4
|
+
import { InputPasswordShowPassword } from './show-password';
|
|
4
5
|
|
|
5
6
|
export const INPUT_PASSWORD_ROUTES: Routes = {
|
|
6
7
|
'input-password': {
|
|
7
8
|
basic: InputPasswordBasic,
|
|
9
|
+
'show-password': InputPasswordShowPassword,
|
|
8
10
|
},
|
|
9
11
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { FC, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { KolForm, KolInputPassword } from '@public-ui/react';
|
|
3
|
+
|
|
4
|
+
export const InputPasswordShowPassword: FC = () => {
|
|
5
|
+
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
|
|
6
|
+
const passwordRef = useRef<HTMLKolInputPasswordElement>(null);
|
|
7
|
+
const handleTogglePasswordClick = () => {
|
|
8
|
+
setIsPasswordVisible(!isPasswordVisible);
|
|
9
|
+
};
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const input = passwordRef.current?.shadowRoot?.querySelector('input');
|
|
12
|
+
if (input) {
|
|
13
|
+
input.type = isPasswordVisible ? 'text' : 'password';
|
|
14
|
+
}
|
|
15
|
+
}, [isPasswordVisible]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<KolForm className="grid gap-4">
|
|
19
|
+
<KolInputPassword
|
|
20
|
+
_placeholder="Mit 'Passwort anzeigen' Button"
|
|
21
|
+
_label="Passwort"
|
|
22
|
+
ref={passwordRef}
|
|
23
|
+
_smartButton={{
|
|
24
|
+
_icon: {
|
|
25
|
+
left: {
|
|
26
|
+
icon: 'codicon codicon-eye',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
_hideLabel: true,
|
|
30
|
+
_label: `Passwort ${isPasswordVisible ? 'ausblenden' : 'einblenden'}`,
|
|
31
|
+
_on: {
|
|
32
|
+
onClick: handleTogglePasswordClick,
|
|
33
|
+
},
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
</KolForm>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useMobile(): boolean {
|
|
4
|
+
const mediaQuery = matchMedia('(max-width: 1023px)');
|
|
5
|
+
const [matches, setMatches] = useState<boolean>(mediaQuery.matches);
|
|
6
|
+
|
|
7
|
+
const handleChange = () => {
|
|
8
|
+
setMatches(mediaQuery.matches);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
handleChange(); // handle initial value
|
|
13
|
+
mediaQuery.addEventListener('change', handleChange);
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
mediaQuery.removeEventListener('change', handleChange);
|
|
17
|
+
};
|
|
18
|
+
}, [mediaQuery]);
|
|
19
|
+
|
|
20
|
+
return matches;
|
|
21
|
+
}
|
package/src/style.scss
CHANGED
|
@@ -19,17 +19,22 @@ hr {
|
|
|
19
19
|
grid-template-columns: auto auto;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
.app-container {
|
|
23
|
-
display: grid;
|
|
24
|
-
grid-template-columns: 360px auto;
|
|
25
|
-
height: 100%;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
22
|
.app-sidebar {
|
|
29
|
-
border-right: 1px solid gray;
|
|
30
23
|
font-family: sans-serif;
|
|
31
24
|
}
|
|
32
25
|
|
|
26
|
+
@media (min-width: 1024px) {
|
|
27
|
+
.app-container {
|
|
28
|
+
display: grid;
|
|
29
|
+
grid-template-columns: 360px auto;
|
|
30
|
+
height: 100%;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.app-sidebar {
|
|
34
|
+
border-right: 1px solid gray;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
@media print {
|
|
34
39
|
.no-print,
|
|
35
40
|
.no-print * {
|