@soul-refiner/design-system 0.2.103 → 0.2.105
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/dist/components/hooks/click-outside.d.ts +2 -0
- package/dist/components/hooks/click-outside.js +10 -0
- package/dist/components/hooks/event-listenter.d.ts +1 -0
- package/dist/components/hooks/event-listenter.js +15 -0
- package/dist/components/hooks/hover.d.ts +2 -0
- package/dist/components/hooks/hover.js +9 -0
- package/dist/components/hooks/index.d.ts +4 -0
- package/dist/components/hooks/index.js +4 -0
- package/dist/components/hooks/window-size.d.ts +4 -0
- package/dist/components/hooks/window-size.js +13 -0
- package/dist/components/iconography/avatar/avatar.d.ts +3 -1
- package/dist/components/iconography/avatar/avatar.js +29 -12
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/input/text_input/text_input.d.ts +2 -1
- package/dist/components/input/text_input/text_input.js +5 -3
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEventListener } from './event-listenter';
|
|
3
|
+
export const useClickOutside = (ref, cb) => {
|
|
4
|
+
useEventListener('click', (e) => {
|
|
5
|
+
if (ref?.current == null ||
|
|
6
|
+
ref?.current?.contains(e.target))
|
|
7
|
+
return;
|
|
8
|
+
cb(e);
|
|
9
|
+
}, document);
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useEventListener: (eventType: string, callback: (...args: any[]) => unknown, element?: Window & typeof globalThis) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export const useEventListener = (eventType, callback, element = window) => {
|
|
4
|
+
const callbackRef = React.useRef(callback);
|
|
5
|
+
React.useEffect(() => {
|
|
6
|
+
callbackRef.current = callback;
|
|
7
|
+
}, [callback]);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (element == null)
|
|
10
|
+
return;
|
|
11
|
+
const handler = (e) => callbackRef.current(e);
|
|
12
|
+
element.addEventListener(eventType, handler);
|
|
13
|
+
return () => element.removeEventListener(eventType, handler);
|
|
14
|
+
}, [eventType, element]);
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useEventListener } from './event-listenter';
|
|
4
|
+
export const useHover = (ref) => {
|
|
5
|
+
const [hovered, setHovered] = React.useState(false);
|
|
6
|
+
useEventListener('mouseover', () => setHovered(true), ref?.current);
|
|
7
|
+
useEventListener('mouseout', () => setHovered(false), ref?.current);
|
|
8
|
+
return hovered;
|
|
9
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useEventListener } from './event-listenter';
|
|
4
|
+
export const useWindowSize = () => {
|
|
5
|
+
const [windowSize, setWindowSize] = React.useState({
|
|
6
|
+
width: window.innerWidth,
|
|
7
|
+
height: window.innerHeight,
|
|
8
|
+
});
|
|
9
|
+
useEventListener('resize', () => {
|
|
10
|
+
setWindowSize({ width: window.innerWidth, height: window.innerHeight });
|
|
11
|
+
});
|
|
12
|
+
return windowSize;
|
|
13
|
+
};
|
|
@@ -15,13 +15,15 @@ export interface AvatarProps extends NativeProps {
|
|
|
15
15
|
textPosition?: 'left' | 'right';
|
|
16
16
|
title?: React.ReactNode;
|
|
17
17
|
tooltipContent?: React.ReactElement;
|
|
18
|
+
tooltipSx?: string;
|
|
19
|
+
tooltipWrapperId?: string;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
*
|
|
21
23
|
* Avatar
|
|
22
24
|
*/
|
|
23
25
|
declare const Avatar: {
|
|
24
|
-
({ as, href, image, size, status, subtitle, sx, textPosition, title, tooltipContent, ...rest }: AvatarProps): React.JSX.Element;
|
|
26
|
+
({ as, href, image, size, status, subtitle, sx, textPosition, title, tooltipContent, tooltipSx, tooltipWrapperId, ...rest }: AvatarProps): React.JSX.Element;
|
|
25
27
|
displayName: string;
|
|
26
28
|
Group: {
|
|
27
29
|
({ children, numDisplayed, total }: AvatarGroupProps): React.JSX.Element;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
|
-
import { Box, H, P } from '../../';
|
|
4
|
+
import { Box, H, P, Portal } from '../../';
|
|
5
5
|
import { Approved, Busy, Declined, Default, Focus, Locked, Offline, Online, Subscribed, } from './icons';
|
|
6
|
+
import { useHover } from '../../../';
|
|
6
7
|
/**
|
|
7
8
|
* Lookup tables for sizes
|
|
8
9
|
*/
|
|
@@ -57,16 +58,14 @@ const iconOffsetY = {
|
|
|
57
58
|
*
|
|
58
59
|
* Avatar
|
|
59
60
|
*/
|
|
60
|
-
const Avatar = ({ as = 'button', href, image, size = 64, status, subtitle, sx, textPosition = 'left', title, tooltipContent, ...rest }) => {
|
|
61
|
+
const Avatar = ({ as = 'button', href, image, size = 64, status, subtitle, sx, textPosition = 'left', title, tooltipContent, tooltipSx, tooltipWrapperId = 'avatar-tooltip', ...rest }) => {
|
|
61
62
|
const [displayDefault, setDisplayDefault] = React.useState(false);
|
|
63
|
+
const componentWrapperRef = React.useRef(null);
|
|
64
|
+
const tooltipRef = React.useRef(null);
|
|
65
|
+
const hovered = useHover(componentWrapperRef);
|
|
66
|
+
const tooltipHovered = useHover(tooltipRef);
|
|
62
67
|
const Icon = iconReference?.[status ?? 'none'];
|
|
63
|
-
return (React.createElement(
|
|
64
|
-
position: relative;
|
|
65
|
-
&:hover > div:nth-of-type(2) {
|
|
66
|
-
display: flex;
|
|
67
|
-
}
|
|
68
|
-
${sx}
|
|
69
|
-
`, ...rest },
|
|
68
|
+
return (React.createElement(ComponentWrapper, { id: "avatar-tooltip", ref: componentWrapperRef, "$sx": sx, ...rest },
|
|
70
69
|
React.createElement(Container, { as: as, "$size": size, href: href },
|
|
71
70
|
!displayDefault && (React.createElement("img", { src: image ?? '', onError: () => setDisplayDefault(true) })),
|
|
72
71
|
displayDefault && React.createElement(Default, null),
|
|
@@ -75,9 +74,26 @@ const Avatar = ({ as = 'button', href, image, size = 64, status, subtitle, sx, t
|
|
|
75
74
|
(title || subtitle) && (React.createElement(TextContainer, { "$textPosition": textPosition },
|
|
76
75
|
title && (React.createElement(H, { as: "h3", "$bold": true, "$color": "grey-2", "$textClampLines": 1, sx: "font-size: 26px;" }, title)),
|
|
77
76
|
subtitle && (React.createElement(P, { "$color": "grey-4", "$textClampLines": 1 }, subtitle)))),
|
|
78
|
-
tooltipContent && React.createElement(
|
|
77
|
+
tooltipContent && (React.createElement(Portal, { wrapperId: tooltipWrapperId },
|
|
78
|
+
React.createElement(TooltipContainer, { id: "tooltip-container", ref: tooltipRef, "$sx": `${hovered || tooltipHovered ? 'display: flex' : 'display: none'}; ${tooltipSx}` }, tooltipContent)))));
|
|
79
79
|
};
|
|
80
80
|
Avatar.displayName = 'Avatar';
|
|
81
|
+
const ComponentWrapper = styled.div `
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
gap: 18px;
|
|
85
|
+
flex: none;
|
|
86
|
+
flex-flow: row;
|
|
87
|
+
flex-direction: row;
|
|
88
|
+
justify-content: normal;
|
|
89
|
+
background-color: var(--page-bg);
|
|
90
|
+
box-shadow: none;
|
|
91
|
+
margin: 0px;
|
|
92
|
+
padding: 0px;
|
|
93
|
+
position: relative;
|
|
94
|
+
|
|
95
|
+
${({ $sx }) => ($sx ? $sx : '')};
|
|
96
|
+
`;
|
|
81
97
|
const Container = styled.div `
|
|
82
98
|
flex-shrink: 0;
|
|
83
99
|
display: flex;
|
|
@@ -115,13 +131,14 @@ const TextContainer = styled.div `
|
|
|
115
131
|
order: ${({ $textPosition }) => ($textPosition === 'left' ? -1 : 1)};
|
|
116
132
|
`;
|
|
117
133
|
const TooltipContainer = styled.div `
|
|
118
|
-
display: none;
|
|
119
134
|
position: absolute;
|
|
120
135
|
top: 100%;
|
|
121
|
-
|
|
136
|
+
z-index: 250;
|
|
122
137
|
background-color: var(--color-white);
|
|
123
138
|
border-radius: 24px;
|
|
124
139
|
box-shadow: var(--elevation-2);
|
|
140
|
+
// pointer-events: none;
|
|
141
|
+
${({ $sx }) => ($sx ? $sx : '')}
|
|
125
142
|
`;
|
|
126
143
|
const Group = ({ children, numDisplayed, total }) => {
|
|
127
144
|
let size = 0;
|
package/dist/components/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export type Props = {
|
|
|
19
19
|
value: string | string[];
|
|
20
20
|
isNumber?: boolean;
|
|
21
21
|
placeIconAtTheEnd?: boolean;
|
|
22
|
+
inputSx?: string;
|
|
22
23
|
};
|
|
23
24
|
interface DisabledProps extends Props {
|
|
24
25
|
disabled?: true;
|
|
@@ -36,5 +37,5 @@ interface WarningProps extends Props {
|
|
|
36
37
|
warning?: true;
|
|
37
38
|
}
|
|
38
39
|
export type TextInputProps = DisabledProps | SuccessfulProps | WarningProps;
|
|
39
|
-
export declare const TextInput: ({ bg, disabled, helperText, icon, label, maxCharacters, multiple, name, onChange, onMultipleChange, placeholder, size, successful, sx, value, warning, isNumber, placeIconAtTheEnd, }: TextInputProps) => React.JSX.Element;
|
|
40
|
+
export declare const TextInput: ({ bg, disabled, helperText, icon, label, maxCharacters, multiple, name, onChange, onMultipleChange, placeholder, size, successful, sx, value, warning, isNumber, placeIconAtTheEnd, inputSx, }: TextInputProps) => React.JSX.Element;
|
|
40
41
|
export {};
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { Chip } from '../../feedback/chip/chip';
|
|
5
5
|
import { CheckmarkCircle, AlertCircle } from '../../../icons';
|
|
6
|
-
export const TextInput = ({ bg = 'var(--color-blue-10)', disabled, helperText, icon, label, maxCharacters, multiple, name, onChange, onMultipleChange, placeholder, size = 'large', successful, sx, value, warning, isNumber, placeIconAtTheEnd = false, }) => {
|
|
6
|
+
export const TextInput = ({ bg = 'var(--color-blue-10)', disabled, helperText, icon, label, maxCharacters, multiple, name, onChange, onMultipleChange, placeholder, size = 'large', successful, sx, value, warning, isNumber, placeIconAtTheEnd = false, inputSx, }) => {
|
|
7
7
|
const id = React.useId();
|
|
8
8
|
const isMultiple = multiple;
|
|
9
9
|
const [multipleValueToAdd, setMultipleValueToAdd] = React.useState('');
|
|
@@ -48,12 +48,12 @@ export const TextInput = ({ bg = 'var(--color-blue-10)', disabled, helperText, i
|
|
|
48
48
|
!placeIconAtTheEnd && icon,
|
|
49
49
|
isMultiple && (React.createElement(MultipleInputWrapper, { onSubmit: handleMultipleAdd },
|
|
50
50
|
value.filter(Boolean).map((item, index) => (React.createElement(Chip, { key: id + item + index, color: "blue", size: "small", onDismiss: () => handleMultipleItemRemoval(item) }, item))),
|
|
51
|
-
React.createElement(Input, { onChange: handleMultipleValueToAdd, onKeyDown: handleMultipleValueDelete, value: multipleValueToAdd, "$size": size }))),
|
|
51
|
+
React.createElement(Input, { onChange: handleMultipleValueToAdd, onKeyDown: handleMultipleValueDelete, value: multipleValueToAdd, "$size": size, "$sx": inputSx }))),
|
|
52
52
|
!isMultiple && (React.createElement(Input, { disabled: disabled, name: name, onChange: onChange, placeholder: placeholder, value: isNumber
|
|
53
53
|
? value
|
|
54
54
|
: maxCharacters
|
|
55
55
|
? value.slice(0, maxCharacters - 1)
|
|
56
|
-
: value, "$size": size, type: isNumber ? 'number' : 'text' })),
|
|
56
|
+
: value, "$size": size, type: isNumber ? 'number' : 'text', "$sx": inputSx })),
|
|
57
57
|
maxCharacters && !isNumber && !placeIconAtTheEnd && (React.createElement(MaxCharactersText, { "$size": size },
|
|
58
58
|
value.length,
|
|
59
59
|
" / ",
|
|
@@ -123,6 +123,8 @@ const Input = styled.input `
|
|
|
123
123
|
&::placeholder {
|
|
124
124
|
color: var(--color-grey-6);
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
${({ $sx }) => ($sx ? $sx : '')}
|
|
126
128
|
`;
|
|
127
129
|
const HelperText = styled.span `
|
|
128
130
|
color: var(--color-grey-4);
|