@sats-group/fresh-fitness-ui-lib 0.1.21 → 0.1.23
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 +3 -2
- package/react/expander/expander.scss +1 -0
- package/react/expander/expander.tsx +1 -3
- package/react/modal/index.ts +2 -0
- package/react/modal/modal.scss +111 -0
- package/react/modal/modal.tsx +98 -0
- package/react/modal/modal.types.ts +8 -0
- package/react/shared/hooks/use-escape.ts +18 -0
- package/react/shared/hooks/use-event.ts +29 -0
- package/react/shared/hooks/use-is-mounted.ts +7 -0
- package/react/shared/hooks/use-previous.ts +17 -0
- package/react/shared/ts/focus-ref.ts +7 -0
- package/react/shared/ts/is-running-on-client.ts +1 -0
- package/react/tab-trapper/tab-trapper.tsx +45 -0
- package/react/tab-trapper/tab-trapper.types.ts +4 -0
- package/tokens/elevation.scss +61 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-group/fresh-fitness-ui-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "Fresh Fitness user interface library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eslint/eslintrc": "^3.3.1",
|
|
25
25
|
"@eslint/js": "^9.19.0",
|
|
26
|
+
"@storybook/react": "^8.5.4",
|
|
26
27
|
"@types/node": "^22.13.1",
|
|
27
28
|
"@types/react": "^19.0.8",
|
|
28
29
|
"@types/react-dom": "^19.0.3",
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"react-collapsed": "^4.2.0",
|
|
53
54
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
54
55
|
},
|
|
55
|
-
"packageManager": "pnpm@10.
|
|
56
|
+
"packageManager": "pnpm@10.8.1+sha512.c50088ba998c67b8ca8c99df8a5e02fd2ae2e2b29aaf238feaa9e124248d3f48f9fb6db2424949ff901cffbb5e0f0cc1ad6aedb602cd29450751d11c35023677"
|
|
56
57
|
}
|
|
@@ -53,9 +53,7 @@ const ExpanderListItem: React.FC<
|
|
|
53
53
|
{...getToggleProps({ 'aria-controls': id })}
|
|
54
54
|
>
|
|
55
55
|
<div className="expander__trigger-title">
|
|
56
|
-
<Text
|
|
57
|
-
{title}
|
|
58
|
-
</Text>
|
|
56
|
+
<Text>{title}</Text>
|
|
59
57
|
</div>
|
|
60
58
|
<div
|
|
61
59
|
className={cn('expander__trigger-flourish', {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
@use '../../tokens/colors.scss';
|
|
2
|
+
@use '../../tokens/elevation.scss';
|
|
3
|
+
@use '../../tokens/spacing.scss';
|
|
4
|
+
|
|
5
|
+
.modal {
|
|
6
|
+
@mixin break {
|
|
7
|
+
@media (min-width: 500px) {
|
|
8
|
+
@content;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
display: grid;
|
|
13
|
+
height: 100%;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
left: 0;
|
|
16
|
+
place-items: center;
|
|
17
|
+
position: fixed;
|
|
18
|
+
top: 0;
|
|
19
|
+
width: 100%;
|
|
20
|
+
z-index: 3;
|
|
21
|
+
|
|
22
|
+
&__background {
|
|
23
|
+
position: fixed;
|
|
24
|
+
top: 0;
|
|
25
|
+
left: 0;
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 100%;
|
|
28
|
+
z-index: 1000;
|
|
29
|
+
background-color: rgba(13, 33, 52, 0.3);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&__header {
|
|
33
|
+
display: grid;
|
|
34
|
+
gap: spacing.$s;
|
|
35
|
+
|
|
36
|
+
&__subheader {
|
|
37
|
+
color: colors.$on-surface-primary-alternate;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&__nav {
|
|
42
|
+
display: flex;
|
|
43
|
+
gap: spacing.$m;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
padding: spacing.$l spacing.$m 0;
|
|
46
|
+
|
|
47
|
+
@include break {
|
|
48
|
+
padding: spacing.$l spacing.$l 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&__inner {
|
|
53
|
+
background-color: colors.$background-secondary-default;
|
|
54
|
+
display: grid;
|
|
55
|
+
gap: spacing.$xl;
|
|
56
|
+
max-width: 640px;
|
|
57
|
+
height: 100%;
|
|
58
|
+
overflow: auto;
|
|
59
|
+
position: relative;
|
|
60
|
+
z-index: 1010;
|
|
61
|
+
|
|
62
|
+
@include break {
|
|
63
|
+
@include elevation.level(24);
|
|
64
|
+
border-radius: spacing.$xs;
|
|
65
|
+
max-height: 95%;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--auto-height {
|
|
70
|
+
.modal__inner {
|
|
71
|
+
@include break {
|
|
72
|
+
height: auto;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&__close {
|
|
78
|
+
display: none;
|
|
79
|
+
|
|
80
|
+
@include break {
|
|
81
|
+
display: block;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&__children {
|
|
86
|
+
padding: 0 spacing.$m spacing.$l;
|
|
87
|
+
|
|
88
|
+
@include break {
|
|
89
|
+
padding: 0 spacing.$l spacing.$l;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&__actions {
|
|
94
|
+
background: inherit;
|
|
95
|
+
border-top: 1px solid colors.$ge-border-default;
|
|
96
|
+
padding: spacing.$s spacing.$m;
|
|
97
|
+
visibility: hidden;
|
|
98
|
+
|
|
99
|
+
&--floating {
|
|
100
|
+
bottom: 0;
|
|
101
|
+
left: 0;
|
|
102
|
+
position: fixed;
|
|
103
|
+
width: 100%;
|
|
104
|
+
visibility: visible;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@include break {
|
|
108
|
+
display: none;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import CloseIcon from '../icons//18/close';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import Text from '../text';
|
|
6
|
+
import Button from '../button';
|
|
7
|
+
import TabTrapper from '../tab-trapper/tab-trapper';
|
|
8
|
+
import useEscape from '../shared/hooks/use-escape';
|
|
9
|
+
import useIsMounted from '../shared/hooks/use-is-mounted';
|
|
10
|
+
|
|
11
|
+
import type { Modal as Props } from './modal.types';
|
|
12
|
+
|
|
13
|
+
const Modal: React.FC<React.PropsWithChildren<Props>> = ({
|
|
14
|
+
autoHeight,
|
|
15
|
+
children,
|
|
16
|
+
closeButtonText,
|
|
17
|
+
headline,
|
|
18
|
+
hide = () => {},
|
|
19
|
+
isVisible,
|
|
20
|
+
subheader,
|
|
21
|
+
}) => {
|
|
22
|
+
const isMounted = useIsMounted();
|
|
23
|
+
|
|
24
|
+
useEscape(hide);
|
|
25
|
+
|
|
26
|
+
// NOTE: It's really important that the first render in the client matches the server HTML (`null`). Otherwise ReactDOM.hydrate messes up the HTML.
|
|
27
|
+
if (!isMounted || !isVisible) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<TabTrapper isActive={true}>
|
|
33
|
+
<div
|
|
34
|
+
className={cn('modal', {
|
|
35
|
+
'modal--auto-height': autoHeight,
|
|
36
|
+
})}
|
|
37
|
+
>
|
|
38
|
+
<div className="modal__inner">
|
|
39
|
+
<div className="modal__nav">
|
|
40
|
+
<div className="modal__header">
|
|
41
|
+
{headline && (
|
|
42
|
+
<Text
|
|
43
|
+
className="modal__header__headline"
|
|
44
|
+
size={Text.sizes.header2}
|
|
45
|
+
theme={Text.themes.emphasis}
|
|
46
|
+
variant={Text.variants.content}
|
|
47
|
+
>
|
|
48
|
+
{headline}
|
|
49
|
+
</Text>
|
|
50
|
+
)}
|
|
51
|
+
{subheader && (
|
|
52
|
+
<Text
|
|
53
|
+
className="modal__header__subheader"
|
|
54
|
+
size={Text.sizes.small}
|
|
55
|
+
variant={Text.variants.content}
|
|
56
|
+
>
|
|
57
|
+
{subheader}
|
|
58
|
+
</Text>
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
<div className="modal__close">
|
|
62
|
+
<Button
|
|
63
|
+
icon={<CloseIcon />}
|
|
64
|
+
iconOnly
|
|
65
|
+
onClick={hide}
|
|
66
|
+
size={Button.sizes.small}
|
|
67
|
+
text={closeButtonText}
|
|
68
|
+
theme={Button.themes.secondary}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
<div className="modal__children">{children}</div>
|
|
73
|
+
<div aria-hidden className="modal__actions">
|
|
74
|
+
{/* NOTE: This hidden `__actions` element is the exact same size as the floating one,
|
|
75
|
+
acting as a spacer so all the content can be visible when scrolling down */}
|
|
76
|
+
<Button
|
|
77
|
+
disabled
|
|
78
|
+
text={closeButtonText}
|
|
79
|
+
theme={Button.themes.secondary}
|
|
80
|
+
wide
|
|
81
|
+
/>
|
|
82
|
+
</div>
|
|
83
|
+
<div className="modal__actions modal__actions--floating">
|
|
84
|
+
<Button
|
|
85
|
+
onClick={hide}
|
|
86
|
+
text={closeButtonText}
|
|
87
|
+
theme={Button.themes.secondary}
|
|
88
|
+
wide
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
<div className="modal__background" onClick={hide} />
|
|
93
|
+
</div>
|
|
94
|
+
</TabTrapper>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default Modal;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import useEvent from './use-event';
|
|
4
|
+
|
|
5
|
+
const useEscape = (callback: (event: KeyboardEvent) => void) => {
|
|
6
|
+
const handleKeyDown = useCallback(
|
|
7
|
+
(event: KeyboardEvent) => {
|
|
8
|
+
if (event.keyCode === 27) {
|
|
9
|
+
callback(event);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
[callback],
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
useEvent<KeyboardEvent>('keydown', handleKeyDown);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default useEscape;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import isRunningOnClient from '../ts/is-running-on-client';
|
|
4
|
+
|
|
5
|
+
const defaultTarget = isRunningOnClient ? window : null;
|
|
6
|
+
|
|
7
|
+
const useEvent = <T extends Event = Event>(
|
|
8
|
+
name: string,
|
|
9
|
+
handler: (e: T) => void,
|
|
10
|
+
target: EventTarget | null = defaultTarget,
|
|
11
|
+
) => {
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!name) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!target) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
target.addEventListener(name, handler);
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
target.removeEventListener(name, handler);
|
|
25
|
+
};
|
|
26
|
+
}, [name, handler, target]);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default useEvent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/** Returns the value of `value` from the previous render.
|
|
4
|
+
```js
|
|
5
|
+
const [value, setValue] = useState();
|
|
6
|
+
const previousValue = usePrevious(value);
|
|
7
|
+
```
|
|
8
|
+
*/
|
|
9
|
+
export default function usePrevious<T>(value: T, initialValue?: T) {
|
|
10
|
+
const state = React.useRef(initialValue);
|
|
11
|
+
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
state.current = value;
|
|
14
|
+
}, [value]);
|
|
15
|
+
|
|
16
|
+
return state.current;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default typeof window !== 'undefined';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import focusRef from '../shared/ts/focus-ref';
|
|
4
|
+
|
|
5
|
+
import usePrevious from '../shared/hooks/use-previous';
|
|
6
|
+
|
|
7
|
+
import type { TabTrapper as Props } from './tab-trapper.types';
|
|
8
|
+
|
|
9
|
+
const TabTrapper: React.FunctionComponent<React.PropsWithChildren<Props>> = ({
|
|
10
|
+
children,
|
|
11
|
+
className,
|
|
12
|
+
isActive,
|
|
13
|
+
}) => {
|
|
14
|
+
const wasActive = usePrevious(isActive);
|
|
15
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
16
|
+
const previouslyFocusedElement = useRef<HTMLElement | null>(null);
|
|
17
|
+
|
|
18
|
+
const focusContent = () => focusRef(contentRef);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!wasActive && isActive) {
|
|
22
|
+
previouslyFocusedElement.current = document.activeElement as HTMLElement;
|
|
23
|
+
focusContent();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (wasActive && !isActive) {
|
|
27
|
+
focusRef(previouslyFocusedElement);
|
|
28
|
+
}
|
|
29
|
+
}, [isActive]);
|
|
30
|
+
|
|
31
|
+
// NOTE: This happens on unmount only
|
|
32
|
+
useEffect(() => () => focusRef(previouslyFocusedElement), []);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
{isActive ? <div onFocus={focusContent} tabIndex={0} /> : null}
|
|
37
|
+
<div className={className} ref={contentRef} tabIndex={-1}>
|
|
38
|
+
{children}
|
|
39
|
+
</div>
|
|
40
|
+
{isActive ? <div onFocus={focusContent} tabIndex={0} /> : null}
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default TabTrapper;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
@use "sass:map";
|
|
2
|
+
|
|
3
|
+
$levels: (
|
|
4
|
+
1: (
|
|
5
|
+
0px 0px 4px rgba(black, 0.08),
|
|
6
|
+
0px 1px 2px rgba(black, 0.06),
|
|
7
|
+
0px 1px 4px rgba(black, 0.14),
|
|
8
|
+
),
|
|
9
|
+
2: (
|
|
10
|
+
0px 1px 1px rgba(black, 0.08),
|
|
11
|
+
0px 1px 5px rgba(black, 0.12),
|
|
12
|
+
0px 2px 9px rgba(black, 0.1),
|
|
13
|
+
),
|
|
14
|
+
3: (
|
|
15
|
+
0px 3px 3px rgba(black, 0.08),
|
|
16
|
+
0px 3px 4px rgba(black, 0.1),
|
|
17
|
+
0px 1px 10px rgba(black, 0.08),
|
|
18
|
+
),
|
|
19
|
+
4: (
|
|
20
|
+
0px 1px 10px rgba(black, 0.08),
|
|
21
|
+
0px 4px 5px rgba(black, 0.1),
|
|
22
|
+
0px 2px 4px rgba(black, 0.1),
|
|
23
|
+
),
|
|
24
|
+
6: (
|
|
25
|
+
0px 1px 18px rgba(black, 0.08),
|
|
26
|
+
0px 6px 10px rgba(black, 0.1),
|
|
27
|
+
0px 3px 5px rgba(black, 0.1),
|
|
28
|
+
),
|
|
29
|
+
8: (
|
|
30
|
+
0px 3px 14px rgba(black, 0.08),
|
|
31
|
+
0px 8px 10px rgba(black, 0.1),
|
|
32
|
+
0px 5px 5px rgba(black, 0.1),
|
|
33
|
+
),
|
|
34
|
+
12: (
|
|
35
|
+
0px 5px 22px rgba(black, 0.08),
|
|
36
|
+
0px 12px 17px rgba(black, 0.1),
|
|
37
|
+
0px 7px 8px rgba(black, 0.1),
|
|
38
|
+
),
|
|
39
|
+
16: (
|
|
40
|
+
0px 7px 30px rgba(black, 0.08),
|
|
41
|
+
0px 16px 24px rgba(black, 0.1),
|
|
42
|
+
0px 8px 10px rgba(black, 0.1),
|
|
43
|
+
),
|
|
44
|
+
24: (
|
|
45
|
+
0px 9px 46px rgba(black, 0.08),
|
|
46
|
+
0px 24px 38px rgba(black, 0.1),
|
|
47
|
+
0px 11px 15px rgba(black, 0.1),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
@mixin level($level) {
|
|
52
|
+
@if map.has-key($levels, $level) {
|
|
53
|
+
box-shadow: map.get($levels, $level);
|
|
54
|
+
} @else {
|
|
55
|
+
@error "Level #{$level} does not exist.";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@mixin unset {
|
|
60
|
+
box-shadow: none;
|
|
61
|
+
}
|