@wonderflow/react-components 3.0.0-beta.13 → 3.0.0-beta.17
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/datetime/datetime.d.ts +2 -2
- package/datetime/datetime.js +5 -2
- package/dropdown/dropdown.js +19 -14
- package/dropdown/dropdown.module.css +1 -1
- package/dropdown/item/dropdown-item.js +1 -1
- package/package.json +1 -1
- package/textfield/textfield.js +2 -2
- package/themes/dark.css +1 -1
- package/themes/light.css +1 -1
- package/title/title.module.css +1 -1
- package/tooltip/tooltip.js +6 -6
- package/tooltip/tooltip.module.css +1 -1
package/datetime/datetime.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HTMLAttributes } from 'react';
|
|
2
2
|
export declare type DatetimeProps = HTMLAttributes<HTMLTimeElement> & {
|
|
3
3
|
date: string;
|
|
4
|
-
locale?: string;
|
|
4
|
+
locale?: string | string[];
|
|
5
5
|
options?: Intl.DateTimeFormatOptions;
|
|
6
6
|
};
|
|
7
|
-
export declare const Datetime: ({ date, locale, options }: DatetimeProps) => JSX.Element;
|
|
7
|
+
export declare const Datetime: ({ date, locale, options, ...otherProps }: DatetimeProps) => JSX.Element;
|
package/datetime/datetime.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
export const Datetime = ({ date, locale = 'en-US', options }) => {
|
|
3
|
+
export const Datetime = ({ date, locale = 'en-US', options, ...otherProps }) => {
|
|
4
4
|
const [datetime, setDateTime] = useState('');
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
const timeDate = new Date(date);
|
|
7
7
|
const humanDate = new Intl.DateTimeFormat(locale, {
|
|
8
|
+
year: 'numeric',
|
|
9
|
+
month: 'long',
|
|
10
|
+
day: 'numeric',
|
|
8
11
|
...options
|
|
9
12
|
}).format(timeDate);
|
|
10
13
|
setDateTime(humanDate);
|
|
11
14
|
}, [date, locale, options]);
|
|
12
|
-
return (_jsx("time", { dateTime: date, children: datetime }, void 0));
|
|
15
|
+
return (_jsx("time", { dateTime: date, ...otherProps, children: datetime }, void 0));
|
|
13
16
|
};
|
package/dropdown/dropdown.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import clsx from 'clsx';
|
|
3
2
|
import { useState, Children, cloneElement, useRef, forwardRef } from 'react';
|
|
4
|
-
import { useKeyPress,
|
|
3
|
+
import { useKeyPress, useFocusWithin } from 'ahooks';
|
|
5
4
|
import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
|
|
6
5
|
import { useUIDSeed } from 'react-uid';
|
|
7
6
|
import { DropdownMenu } from './menu/dropdown-menu';
|
|
@@ -9,6 +8,7 @@ import { DropdownItem } from './item/dropdown-item';
|
|
|
9
8
|
import { DropdownItemCheckbox } from './item-checkbox/dropdown-item-checkbox';
|
|
10
9
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
11
10
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
11
|
+
import clsx from 'clsx';
|
|
12
12
|
const DropdownAnimation = {
|
|
13
13
|
visible: {
|
|
14
14
|
y: 0,
|
|
@@ -27,37 +27,42 @@ const DropdownAnimation = {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
export const Dropdown = forwardRef(({
|
|
30
|
+
export const Dropdown = forwardRef(({ children, trigger, offset = 8, placement = 'auto-start', className }, forwardedRef) => {
|
|
31
31
|
const renderedChildren = Children.toArray(children).filter(Boolean);
|
|
32
32
|
const seedID = useUIDSeed();
|
|
33
|
-
const
|
|
33
|
+
const dropdownRef = useRef(forwardedRef);
|
|
34
34
|
const [isOpen, setIsOpen] = useState(false);
|
|
35
35
|
const { getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
|
|
36
36
|
delayShow: 0,
|
|
37
|
-
delayHide:
|
|
37
|
+
delayHide: 0,
|
|
38
38
|
trigger: ['click'],
|
|
39
39
|
visible: isOpen,
|
|
40
40
|
closeOnTriggerHidden: true,
|
|
41
41
|
onVisibleChange: setIsOpen,
|
|
42
42
|
placement: placement,
|
|
43
43
|
offset: [0, offset],
|
|
44
|
-
closeOnOutsideClick:
|
|
44
|
+
closeOnOutsideClick: true
|
|
45
|
+
});
|
|
46
|
+
const isFocusWithin = useFocusWithin(dropdownRef, {
|
|
47
|
+
onBlur: (e) => {
|
|
48
|
+
if (e.relatedTarget && visible) {
|
|
49
|
+
setIsOpen(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
45
52
|
});
|
|
46
|
-
const isFocusWithin = useFocusWithin(popupRef);
|
|
47
|
-
useClickAway(() => {
|
|
48
|
-
setIsOpen(false);
|
|
49
|
-
}, popupRef);
|
|
50
53
|
useKeyPress('esc', () => setIsOpen(false));
|
|
51
|
-
return (_jsxs("div", { ref:
|
|
54
|
+
return (_jsxs("div", { ref: dropdownRef, className: clsx(DropdownClass, className), "data-dropdown-has-focus": isFocusWithin, children: [Children.map(trigger, (child) => cloneElement(child, {
|
|
52
55
|
ref: setTriggerRef,
|
|
53
56
|
id: seedID('dropdown-trigger'),
|
|
57
|
+
key: seedID('dropdown-trigger'),
|
|
54
58
|
'aria-haspopup': 'true',
|
|
55
59
|
'aria-controls': seedID('dropdown-menu'),
|
|
56
|
-
'aria-expanded': isOpen
|
|
57
|
-
|
|
60
|
+
'aria-expanded': isOpen,
|
|
61
|
+
'data-open': isOpen
|
|
62
|
+
})), _jsx(AnimatePresence, { children: visible && (_jsx("div", { ref: setTooltipRef, role: "tooltip", id: seedID('tooltip-content'), ...getTooltipProps({ className: PopUp }), children: _jsx(motion.div, { variants: DropdownAnimation, initial: "hidden", animate: "visible", exit: "hidden", children: Children.map(renderedChildren, (child) => cloneElement(child, {
|
|
58
63
|
id: seedID('dropdown-menu'),
|
|
59
64
|
'aria-labelledby': seedID('dropdown-trigger')
|
|
60
|
-
})) }, void 0) },
|
|
65
|
+
})) }, void 0) }, seedID('tooltip-content'))) }, void 0)] }, void 0));
|
|
61
66
|
});
|
|
62
67
|
Dropdown.displayName = 'Dropdown';
|
|
63
68
|
Dropdown.Menu = DropdownMenu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.Dropdown{display:
|
|
1
|
+
.Dropdown{display:contents}.PopUp{inline-size:max-content;z-index:2}
|
|
@@ -17,7 +17,7 @@ export const DropdownItem = forwardRef(({ className, children, onClick, icon, di
|
|
|
17
17
|
}, [handleClick, onClick]);
|
|
18
18
|
const InnerContent = useMemo(() => (_jsxs(Stack, { direction: "row", as: "span", fill: false, horizontalAlign: isIconRight ? 'space-between' : 'start', verticalAlign: "center", columnGap: 8, horizontalPadding: 16, verticalPadding: 8, "data-dropdown-icon-right": isIconRight, "data-dropdown-has-icon": Boolean(icon), "data-dropdown-padding": padding, style: { inlineSize: '100%' }, children: [icon && (_jsx(Icon, { className: IconClass, name: icon, dimension: dimension === 'small' ? 14 : 16 }, void 0)), children] }, void 0)), [children, dimension, icon, isIconRight, padding]);
|
|
19
19
|
return (_jsx(Wrapper, { ref: itemRef, role: "menuitem", className: clsx(DropdownItemClass, className), onClick: disabled ? undefined : triggerClick, onKeyDown: disabled ? undefined : handleKeyDown, tabIndex: tabIndex, "aria-disabled": disabled, type: Wrapper === 'button' ? 'button' : undefined, "data-dropdown-item-dimension": dimension, ...props, children: description
|
|
20
|
-
? (_jsx(Tooltip, { fill: true, show: focused, placement: "right-start", trigger: InnerContent, children: description }, void 0))
|
|
20
|
+
? (_jsx(Tooltip, { fill: true, show: focused, placement: "right-start", interactive: true, trigger: InnerContent, children: description }, void 0))
|
|
21
21
|
: InnerContent }, void 0));
|
|
22
22
|
});
|
|
23
23
|
DropdownItem.displayName = 'Dropdown.Item';
|
package/package.json
CHANGED
package/textfield/textfield.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseField } from './base-field';
|
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import { useUIDSeed } from 'react-uid';
|
|
7
7
|
import { Textfield as TextfieldClass, FieldContainer, InputField, Icon as IconClass, IconButton as IconButtonClass } from './textfield.module.css';
|
|
8
|
-
export const Textfield = forwardRef(({ children, className, disabled = false, icon, label, textarea, readOnly, invalid, iconPosition = 'right', dimension = 'regular', type, onChange, ...otherProps }, forwardedRef) => {
|
|
8
|
+
export const Textfield = forwardRef(({ children, className, disabled = false, icon, label, textarea, readOnly, invalid, iconPosition = 'right', dimension = 'regular', type, style, onChange, ...otherProps }, forwardedRef) => {
|
|
9
9
|
const [passwordVisible, setPasswordVisible] = useState(false);
|
|
10
10
|
const seedID = useUIDSeed();
|
|
11
11
|
const isPassword = type === 'password';
|
|
@@ -28,7 +28,7 @@ export const Textfield = forwardRef(({ children, className, disabled = false, ic
|
|
|
28
28
|
disabled,
|
|
29
29
|
onChange
|
|
30
30
|
};
|
|
31
|
-
return (_jsxs(Stack, { as: "fieldset", rowGap: 4, className: clsx(TextfieldClass, className), "data-textfield-has-icon": isPassword || Boolean(icon), "data-textfield-icon-position": iconPosition, "data-textfield-dimension": dimension, "data-textfield-invalid": invalid, "aria-disabled": disabled, horizontalAlign: "stretch", verticalAlign: "start", tabIndex: disabled ? 0 : undefined, children: [label && _jsx(Text, { as: "label", size: dimension === 'small' ? 14 : 16, htmlFor: seedID('field'), children: label }, void 0), _jsxs("div", { className: FieldContainer, children: [textarea
|
|
31
|
+
return (_jsxs(Stack, { as: "fieldset", rowGap: 4, className: clsx(TextfieldClass, className), "data-textfield-has-icon": isPassword || Boolean(icon), "data-textfield-icon-position": iconPosition, "data-textfield-dimension": dimension, "data-textfield-invalid": invalid, "aria-disabled": disabled, horizontalAlign: "stretch", verticalAlign: "start", tabIndex: disabled ? 0 : undefined, style: style, children: [label && _jsx(Text, { as: "label", size: dimension === 'small' ? 14 : 16, htmlFor: seedID('field'), children: label }, void 0), _jsxs("div", { className: FieldContainer, children: [textarea
|
|
32
32
|
? (_jsx(BaseField, { ref: forwardedRef, as: "textarea", id: seedID('field'), ...commonProps, ...otherProps }, void 0))
|
|
33
33
|
: (_jsx(BaseField, { className: InputField, id: seedID('field'), ref: forwardedRef, type: passwordVisible ? 'text' : type, ...commonProps, ...otherProps }, void 0)), isPassword && (_jsx(IconButton, { className: IconButtonClass, dimension: actionSizes[dimension], onClick: handlePasswordVisibility, kind: "flat", "aria-label": "Reveal password", icon: passwordVisible ? 'eye-slash' : 'eye' }, void 0)), !textarea && icon && type !== 'password' && (_jsx(Icon, { className: IconClass, name: icon, dimension: iconSizes[dimension] }, void 0))] }, void 0)] }, void 0));
|
|
34
34
|
});
|
package/themes/dark.css
CHANGED
package/themes/light.css
CHANGED
package/title/title.module.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.Title:is(.H1,.H2,.H3,.H4,.H5,.H6,.Display){--lh:
|
|
1
|
+
.Title:is(.H1,.H2,.H3,.H4,.H5,.H6,.Display){--lh:1.5;color:var(--heading-foreground);display:block;font-size:var(--fs-max);line-height:1.2;max-inline-size:var(--maxW,initial);min-block-size:.01vh;overflow-wrap:break-word;text-align:var(--tAlign)}.Title[data-title-line-height=small]:is(.H1,.H2,.H3,.H4,.H5,.H6,.Display){--lh:1.2}.Title[data-title-line-height=large]:is(.H1,.H2,.H3,.H4,.H5,.H6,.Display){line-height:1.5}.Title:is(.H6){--fs-min:0.78rem;--fs-max:1.00rem;font-weight:700}.Title:is(.H5){--fs-min:1rem;--fs-max:1.33rem;font-weight:700}.Title:is(.H5):before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title:is(.H4){--fs-min:1.33rem;--fs-max:1.77rem;font-weight:700}.Title:is(.H4):before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title:is(.H3){--fs-min:1.77rem;--fs-max:2.37rem;font-weight:800}.Title:is(.H3):before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title:is(.H2){--fs-min:2.37rem;--fs-max:3.16rem;font-weight:800}.Title:is(.H2):before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title:is(.H1){--fs-min:3.16rem;--fs-max:4.2rem;font-weight:800}.Title:is(.H1):before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title.Display{--fs-min:4.2rem;--fs-max:5.6rem;font-weight:800}.Title.Display:before{content:"";display:block;height:0;margin-top:calc((1 - var(--lh))*.6em);width:0}.Title[data-title-responsive=true]{font-size:var(--fs-min)}@media (min-width:48em){.Title[data-title-responsive=true]{font-size:var(--fs-max)}}
|
package/tooltip/tooltip.js
CHANGED
|
@@ -7,17 +7,17 @@ import { Tooltip as TooltipClass, Arrow, Trigger } from './tooltip.module.css';
|
|
|
7
7
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
8
8
|
export const Tooltip = ({ children, trigger, placement = 'bottom-start', show, style, maxWidth = '40ch', fill = false, interactive = false, delay = 500 }) => {
|
|
9
9
|
const seedID = useUIDSeed();
|
|
10
|
-
const [
|
|
10
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
11
11
|
const tooltipContainerRef = useRef(null);
|
|
12
|
-
useKeyPress('esc', () =>
|
|
12
|
+
useKeyPress('esc', () => setIsOpen(false));
|
|
13
13
|
const { getArrowProps, getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
|
|
14
14
|
delayShow: delay,
|
|
15
15
|
delayHide: 300,
|
|
16
16
|
trigger: ['hover'],
|
|
17
|
-
visible: show ||
|
|
17
|
+
visible: show || isOpen,
|
|
18
18
|
closeOnTriggerHidden: true,
|
|
19
19
|
interactive: interactive,
|
|
20
|
-
onVisibleChange:
|
|
20
|
+
onVisibleChange: setIsOpen,
|
|
21
21
|
placement: placement,
|
|
22
22
|
offset: [0, 16]
|
|
23
23
|
}, {
|
|
@@ -25,10 +25,10 @@ export const Tooltip = ({ children, trigger, placement = 'bottom-start', show, s
|
|
|
25
25
|
});
|
|
26
26
|
const isFocusWithin = useFocusWithin(tooltipContainerRef, {
|
|
27
27
|
onFocus: () => {
|
|
28
|
-
|
|
28
|
+
setIsOpen(true);
|
|
29
29
|
},
|
|
30
30
|
onBlur: (e) => {
|
|
31
|
-
(e.target?.parentElement !== tooltipContainerRef.current) &&
|
|
31
|
+
(e.target?.parentElement !== tooltipContainerRef.current) && setIsOpen(false);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
const dynamycStyle = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.Tooltip{word-wrap:break-word;background-color:#31363f;border-radius:.22rem;font-size:.89rem;max-inline-size:var(--maxW);padding:.44rem .89rem;position:relative;z-index:2}.Tooltip[data-popper-reference-hidden=true]{pointer-events:none;visibility:hidden}.Trigger{display:
|
|
1
|
+
.Tooltip{word-wrap:break-word;background-color:#31363f;border-radius:.22rem;font-size:.89rem;max-inline-size:var(--maxW);padding:.44rem .89rem;position:relative;z-index:2}.Tooltip[data-popper-reference-hidden=true]{pointer-events:none;visibility:hidden}.Trigger{display:contents}.Arrow:before{background-color:#31363f;block-size:12px;content:"";inline-size:12px;position:absolute;transform:rotate(45deg);visibility:visible}.Tooltip[data-popper-reference-hidden=true] .Arrow{pointer-events:none;visibility:hidden}.Tooltip[data-popper-placement^=top] .Arrow{bottom:6px}.Tooltip[data-popper-placement^=top] .Arrow:before{transform:translateX(-50%) rotate(45deg)}.Tooltip[data-popper-placement^=left] .Arrow{right:6px}.Tooltip[data-popper-placement^=left] .Arrow:before{transform:translateY(-50%) rotate(45deg)}.Tooltip[data-popper-placement^=bottom] .Arrow{top:-6px}.Tooltip[data-popper-placement^=bottom] .Arrow:before{transform:translateX(-50%) rotate(45deg)}.Tooltip[data-popper-placement^=right] .Arrow{left:-6px}.Tooltip[data-popper-placement^=right] .Arrow:before{transform:translateY(-50%) rotate(45deg)}
|