@apple-pie/slice 0.0.1 → 0.0.3
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/cjs/chunks/Avatar-8-wPWe0V.js +68 -0
- package/dist/cjs/chunks/AvatarGroup-CVKmgBbD.js +39 -0
- package/dist/cjs/chunks/Badge-CMapJCij.js +41 -0
- package/dist/cjs/chunks/CheckBox-7AACxrdZ.js +76 -0
- package/dist/cjs/chunks/DivInput-BKKJTFeV.js +204 -0
- package/dist/cjs/chunks/DocIcons-BRWOzK96.js +41 -0
- package/dist/cjs/chunks/Dot-Dnr9M9na.js +80 -0
- package/dist/cjs/chunks/DrggablePanel-C6TPsDB-.js +302 -0
- package/dist/cjs/chunks/DropDown-D9sf_m2I.js +154 -0
- package/dist/cjs/chunks/EditorButtonBar-CUNDgRQd.js +244 -0
- package/dist/cjs/chunks/ErrorSummary-Dv44onsV.js +42 -0
- package/dist/cjs/chunks/FlexDiv-DZBpswHV.js +103 -0
- package/dist/cjs/chunks/Grouper-_kd2nU78.js +50 -0
- package/dist/cjs/chunks/IconButton-BfsPlKTb.js +84 -0
- package/dist/cjs/chunks/Logos-DSlAUz8l.js +119 -0
- package/dist/cjs/chunks/MessageInput-CiHFo2j8.js +399 -0
- package/dist/cjs/chunks/Overlay-DwCPvGB5.js +45 -0
- package/dist/cjs/chunks/Pager-CFtZ0IIW.js +42 -0
- package/dist/cjs/chunks/ProgressIndicator-C5oB7Mky.js +121 -0
- package/dist/cjs/chunks/RadioButton-e_y2qiPE.js +65 -0
- package/dist/cjs/chunks/RadioButtonList-I81UwHmM.js +116 -0
- package/dist/cjs/chunks/Slider-C-gn7Sby.js +285 -0
- package/dist/cjs/chunks/Spacer-BEY2-_PB.js +16 -0
- package/dist/cjs/chunks/Switch-CtkFtogd.js +43 -0
- package/dist/cjs/chunks/TabBar-D3bj4pjj.js +176 -0
- package/dist/cjs/chunks/TextArea-B1oKK3_b.js +153 -0
- package/dist/cjs/chunks/TextField-CiQdPP5E.js +248 -0
- package/dist/cjs/chunks/Tip-C2pzExut.js +91 -0
- package/dist/cjs/chunks/Toast-DrijUwoL.js +141 -0
- package/dist/cjs/chunks/UIButton-CH4p-8yq.js +317 -0
- package/dist/cjs/chunks/UIButtonBar-0fHPB0ww.js +58 -0
- package/dist/cjs/chunks/UICard-DBDSyT7E.js +36 -0
- package/dist/cjs/chunks/UIChip-kjhvRrOV.js +93 -0
- package/dist/cjs/chunks/UIFileIcon-ZrbDIeYz.js +54 -0
- package/dist/cjs/chunks/UILabel-DkBE2AIt.js +116 -0
- package/dist/cjs/chunks/_types-CoWzQFsT.js +714 -0
- package/dist/cjs/chunks/sharedTypes-BvTjh6M5.js +9 -0
- package/dist/cjs/chunks/style-inject.es-XZHJH68X.js +30 -0
- package/dist/cjs/chunks/tipStore-C9oV9SIh.js +23 -0
- package/dist/cjs/chunks/toastStore-C-ETP9H6.js +23 -0
- package/dist/cjs/chunks/tslib.es6-4H29ixHs.js +48 -0
- package/dist/cjs/chunks/utils-CbayehuI.js +126 -0
- package/dist/cjs/hooks/useDoubleClick.js +26 -0
- package/dist/cjs/hooks/useKeyboardShortcuts.js +42 -0
- package/dist/cjs/hooks/useLastUpdated.js +53 -0
- package/dist/cjs/hooks/useLocalStore.js +52 -0
- package/dist/cjs/hooks/useObserveResize.js +56 -0
- package/dist/cjs/hooks/useObserveTheme.js +37 -0
- package/dist/cjs/hooks/useTheme.js +86 -0
- package/dist/cjs/hooks/useToolTip.js +36 -0
- package/dist/cjs/hooks/useTrackRenders.js +38 -0
- package/dist/cjs/hooks/useWindow.js +64 -0
- package/dist/cjs/hooks.js +33 -0
- package/dist/cjs/index.js +124 -0
- package/dist/cjs/providers/ThemeProvider.js +55 -0
- package/dist/cjs/providers.js +14 -0
- package/dist/cjs/stores/tip.js +12 -0
- package/dist/cjs/stores/toast.js +12 -0
- package/dist/cjs/stores.js +18 -0
- package/dist/cjs/theme/colors.js +383 -0
- package/dist/cjs/theme/corners.js +14 -0
- package/dist/cjs/theme/elevations.js +17 -0
- package/dist/cjs/theme/themes.js +26 -0
- package/dist/cjs/theme/type.js +316 -0
- package/dist/cjs/theme.js +16 -0
- package/dist/cjs/uikit/Avatar.js +11 -0
- package/dist/cjs/uikit/AvatarGroup.js +12 -0
- package/dist/cjs/uikit/Badge.js +11 -0
- package/dist/cjs/uikit/CheckBox.js +22 -0
- package/dist/cjs/uikit/DivInput.js +13 -0
- package/dist/cjs/uikit/DocIcon.js +18 -0
- package/dist/cjs/uikit/Dot.js +12 -0
- package/dist/cjs/uikit/DraggablePanel.js +21 -0
- package/dist/cjs/uikit/DropDown.js +21 -0
- package/dist/cjs/uikit/EditorButtonBar.js +28 -0
- package/dist/cjs/uikit/ErrorSummary.js +12 -0
- package/dist/cjs/uikit/FlexDiv.js +12 -0
- package/dist/cjs/uikit/Grouper.js +23 -0
- package/dist/cjs/uikit/Icon.js +23 -0
- package/dist/cjs/uikit/IconButton.js +25 -0
- package/dist/cjs/uikit/Logos.js +18 -0
- package/dist/cjs/uikit/MessageInput.js +30 -0
- package/dist/cjs/uikit/Overlay.js +12 -0
- package/dist/cjs/uikit/Pager.js +12 -0
- package/dist/cjs/uikit/Progress.js +21 -0
- package/dist/cjs/uikit/RadioButton.js +26 -0
- package/dist/cjs/uikit/RadioButtonList.js +27 -0
- package/dist/cjs/uikit/Slider.js +13 -0
- package/dist/cjs/uikit/Spacer.js +10 -0
- package/dist/cjs/uikit/Switch.js +12 -0
- package/dist/cjs/uikit/TabBar.js +26 -0
- package/dist/cjs/uikit/TextArea.js +27 -0
- package/dist/cjs/uikit/Textfield.js +28 -0
- package/dist/cjs/uikit/Tip.js +13 -0
- package/dist/cjs/uikit/Toast.js +26 -0
- package/dist/cjs/uikit/UIButton.js +26 -0
- package/dist/cjs/uikit/UIButtonBar.js +26 -0
- package/dist/cjs/uikit/UICard.js +21 -0
- package/dist/cjs/uikit/UIChip.js +22 -0
- package/dist/cjs/uikit/UIFileIcon.js +18 -0
- package/dist/cjs/uikit/UILabel.js +19 -0
- package/dist/esm/chunks/Avatar-D_muqPrW.js +66 -0
- package/dist/esm/chunks/AvatarGroup-D8Xmrn52.js +37 -0
- package/dist/esm/chunks/Badge-PPf5Uvw3.js +39 -0
- package/dist/esm/chunks/CheckBox-CswFI0Xc.js +74 -0
- package/dist/esm/chunks/DivInput-iKFkeU2F.js +202 -0
- package/dist/esm/chunks/DocIcons-CbOX4n8Y.js +39 -0
- package/dist/esm/chunks/Dot-B84UVs2e.js +78 -0
- package/dist/esm/chunks/DrggablePanel-CYYwTmFd.js +300 -0
- package/dist/esm/chunks/DropDown-D4t6EhKL.js +152 -0
- package/dist/esm/chunks/EditorButtonBar-FnMa8Zv2.js +242 -0
- package/dist/esm/chunks/ErrorSummary-DhU5SKPt.js +40 -0
- package/dist/esm/chunks/FlexDiv-CmMpORgn.js +101 -0
- package/dist/esm/chunks/Grouper-BbreOXI9.js +48 -0
- package/dist/esm/chunks/IconButton-CguHGkBM.js +82 -0
- package/dist/esm/chunks/Logos-DwZP-TR2.js +117 -0
- package/dist/esm/chunks/MessageInput-DMHzCwjO.js +397 -0
- package/dist/esm/chunks/Overlay-CCBy7n7H.js +43 -0
- package/dist/esm/chunks/Pager-BsSti93V.js +40 -0
- package/dist/esm/chunks/ProgressIndicator-BVukxMU6.js +118 -0
- package/dist/esm/chunks/RadioButton-B5BxQI0R.js +63 -0
- package/dist/esm/chunks/RadioButtonList-C2z8McAD.js +114 -0
- package/dist/esm/chunks/Slider-C-PcWqTz.js +283 -0
- package/dist/esm/chunks/Spacer-DbZSG5x3.js +14 -0
- package/dist/esm/chunks/Switch-DjfrSiQz.js +41 -0
- package/dist/esm/chunks/TabBar-BSBcgTbd.js +174 -0
- package/dist/esm/chunks/TextArea-COM0UPo2.js +151 -0
- package/dist/esm/chunks/TextField-Bh24bRWs.js +246 -0
- package/dist/esm/chunks/Tip-Ct19Ljul.js +89 -0
- package/dist/esm/chunks/Toast-BR0oMX6z.js +139 -0
- package/dist/esm/chunks/UIButton-DKx-_O8h.js +315 -0
- package/dist/esm/chunks/UIButtonBar-BNdA5eVq.js +56 -0
- package/dist/esm/chunks/UICard-Dn5f3wg8.js +34 -0
- package/dist/esm/chunks/UIChip-DqnGeVyR.js +91 -0
- package/dist/esm/chunks/UIFileIcon-qGxIPsJJ.js +52 -0
- package/dist/esm/chunks/UILabel-RnbodPCS.js +114 -0
- package/dist/esm/chunks/_types-BaYeLEWK.js +712 -0
- package/dist/esm/chunks/sharedTypes-BfZzG1KX.js +9 -0
- package/dist/esm/chunks/style-inject.es-tgCJW-Cu.js +28 -0
- package/dist/esm/chunks/tipStore-nBYJ6tmE.js +17 -0
- package/dist/esm/chunks/toastStore-r3pvNa28.js +17 -0
- package/dist/esm/chunks/tslib.es6-0pkUdtrF.js +45 -0
- package/dist/esm/chunks/utils-BRZK2Drn.js +119 -0
- package/dist/esm/hooks/useDoubleClick.js +24 -0
- package/dist/esm/hooks/useKeyboardShortcuts.js +40 -0
- package/dist/esm/hooks/useLastUpdated.js +51 -0
- package/dist/esm/hooks/useLocalStore.js +50 -0
- package/dist/esm/hooks/useObserveResize.js +54 -0
- package/dist/esm/hooks/useObserveTheme.js +35 -0
- package/dist/esm/hooks/useTheme.js +84 -0
- package/dist/esm/hooks/useToolTip.js +34 -0
- package/dist/esm/hooks/useTrackRenders.js +36 -0
- package/dist/esm/hooks/useWindow.js +62 -0
- package/dist/esm/hooks.js +15 -0
- package/dist/esm/index.js +58 -0
- package/dist/esm/providers/ThemeProvider.js +53 -0
- package/dist/esm/providers.js +8 -0
- package/dist/esm/stores/tip.js +2 -0
- package/dist/esm/stores/toast.js +2 -0
- package/dist/esm/stores.js +3 -0
- package/dist/esm/theme/colors.js +377 -0
- package/dist/esm/theme/corners.js +12 -0
- package/dist/esm/theme/elevations.js +15 -0
- package/dist/esm/theme/themes.js +23 -0
- package/dist/esm/theme/type.js +312 -0
- package/dist/esm/theme.js +5 -0
- package/dist/esm/uikit/Avatar.js +5 -0
- package/dist/esm/uikit/AvatarGroup.js +6 -0
- package/dist/esm/uikit/Badge.js +5 -0
- package/dist/esm/uikit/CheckBox.js +16 -0
- package/dist/esm/uikit/DivInput.js +7 -0
- package/dist/esm/uikit/DocIcon.js +12 -0
- package/dist/esm/uikit/Dot.js +6 -0
- package/dist/esm/uikit/DraggablePanel.js +15 -0
- package/dist/esm/uikit/DropDown.js +15 -0
- package/dist/esm/uikit/EditorButtonBar.js +22 -0
- package/dist/esm/uikit/ErrorSummary.js +6 -0
- package/dist/esm/uikit/FlexDiv.js +6 -0
- package/dist/esm/uikit/Grouper.js +17 -0
- package/dist/esm/uikit/Icon.js +13 -0
- package/dist/esm/uikit/IconButton.js +19 -0
- package/dist/esm/uikit/Logos.js +12 -0
- package/dist/esm/uikit/MessageInput.js +24 -0
- package/dist/esm/uikit/Overlay.js +6 -0
- package/dist/esm/uikit/Pager.js +6 -0
- package/dist/esm/uikit/Progress.js +14 -0
- package/dist/esm/uikit/RadioButton.js +20 -0
- package/dist/esm/uikit/RadioButtonList.js +21 -0
- package/dist/esm/uikit/Slider.js +7 -0
- package/dist/esm/uikit/Spacer.js +4 -0
- package/dist/esm/uikit/Switch.js +6 -0
- package/dist/esm/uikit/TabBar.js +20 -0
- package/dist/esm/uikit/TextArea.js +21 -0
- package/dist/esm/uikit/Textfield.js +22 -0
- package/dist/esm/uikit/Tip.js +7 -0
- package/dist/esm/uikit/Toast.js +16 -0
- package/dist/esm/uikit/UIButton.js +20 -0
- package/dist/esm/uikit/UIButtonBar.js +20 -0
- package/dist/esm/uikit/UICard.js +15 -0
- package/dist/esm/uikit/UIChip.js +16 -0
- package/dist/esm/uikit/UIFileIcon.js +12 -0
- package/dist/esm/uikit/UILabel.js +13 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/providers/ThemeProvider.d.ts +1 -0
- package/dist/types/stores/index.d.ts +2 -0
- package/dist/types/stores/tip/_types.d.ts +8 -0
- package/dist/types/stores/tip/index.d.ts +2 -0
- package/dist/types/stores/tip/tipStore.d.ts +12 -0
- package/dist/types/stores/toast/_types.d.ts +14 -0
- package/dist/types/stores/toast/index.d.ts +2 -0
- package/dist/types/stores/toast/toastStore.d.ts +12 -0
- package/dist/types/theme/elevations/_types.d.ts +10 -0
- package/dist/types/theme/elevations/elevations.d.ts +5 -0
- package/dist/types/theme/index.d.ts +2 -0
- package/dist/types/theme/themes.d.ts +2 -0
- package/dist/types/uikit/FlexDiv/FlexDiv.d.ts +2 -0
- package/dist/types/uikit/FlexDiv/_types.d.ts +1 -0
- package/dist/types/uikit/Toast/Toast.d.ts +1 -1
- package/dist/types/uikit/Toast/_types.d.ts +7 -1
- package/dist/types/uikit/Toast/index.d.ts +1 -1
- package/package.json +84 -5
- package/dist/index.esm.js +0 -5859
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -5911
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-0pkUdtrF.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { motion } from 'motion/react';
|
|
4
|
+
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
5
|
+
import { s as styleInject } from './style-inject.es-tgCJW-Cu.js';
|
|
6
|
+
|
|
7
|
+
var css_248z = ".flexBox-module_row__PWxbe {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowBetween__27lKK {\n\tdisplay: flex;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowStart__nJZnW {\n\tdisplay: flex;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowEnd__dHcOU {\n\tdisplay: flex;\n\tjustify-content: flex-end;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_column__MP2Xd {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStart__Kg8cV {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: flex-start;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStartCenter__zcmtk {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnBetween__157yI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnEnd__u2nwI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-end;\n\talign-items: flex-end;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}\n\n.Switch-module_wrapper__OqM0E {\n\tpadding: var(--switch-padding) !important;\n\twidth: var(--switch-width);\n\theight: var(--switch-height);\n\tborder-radius: 100px;\n\tcursor: pointer;\n\tbackground: var(--switch-bg-color);\n\ttransition: background 0.25s ease-in-out 0s;\n}\n\n.Switch-module_knob__BLGda {\n\twidth: var(--switch-knob-size);\n\theight: var(--switch-knob-size);\n\tbackground: var(--switch-knob-color);\n\tborder-radius: 100%;\n}\n";
|
|
8
|
+
var css = {"wrapper":"Switch-module_wrapper__OqM0E flexBox-module_row__PWxbe","knob":"Switch-module_knob__BLGda flexBox-module_row__PWxbe"};
|
|
9
|
+
styleInject(css_248z);
|
|
10
|
+
|
|
11
|
+
const Switch = React.memo((props) => {
|
|
12
|
+
const { state = false, height = 22, width = 44, padding = 3, bgColorOn = 'var(--feedback-positive)', bgColorOff = 'var(--core-text-disabled)', knobColor = 'var(--core-surface-primary)', onChange = () => null } = props, divAttributes = __rest(props, ["state", "height", "width", "padding", "bgColorOn", "bgColorOff", "knobColor", "onChange"]);
|
|
13
|
+
const { id: divId, className, style } = divAttributes, rest = __rest(divAttributes, ["id", "className", "style"]);
|
|
14
|
+
const divStyle = style !== null && style !== void 0 ? style : {};
|
|
15
|
+
const divClass = className ? ` ${className}` : '';
|
|
16
|
+
const [on, setOn] = useState(state);
|
|
17
|
+
// Sync with prop changes
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setOn(state);
|
|
20
|
+
}, [state]);
|
|
21
|
+
const handleClick = useCallback(() => {
|
|
22
|
+
setOn(!on);
|
|
23
|
+
onChange(!on);
|
|
24
|
+
}, [on, onChange]);
|
|
25
|
+
// Memoize style object
|
|
26
|
+
const justify = useMemo(() => ({ justifyContent: on ? 'flex-end' : 'flex-start' }), [on]);
|
|
27
|
+
// memo css vars
|
|
28
|
+
const cssVars = useMemo(() => {
|
|
29
|
+
return {
|
|
30
|
+
'--switch-width': `${width}px`,
|
|
31
|
+
'--switch-height': `${height}px`,
|
|
32
|
+
'--switch-padding': `${padding}px`,
|
|
33
|
+
'--switch-knob-size': `${height - padding * 2}px`,
|
|
34
|
+
'--switch-knob-color': knobColor,
|
|
35
|
+
'--switch-bg-color': on ? bgColorOn : bgColorOff,
|
|
36
|
+
};
|
|
37
|
+
}, [width, height, padding, bgColorOff, bgColorOn, on, knobColor]);
|
|
38
|
+
return (jsx(motion.div, Object.assign({ id: divId, className: `${css.wrapper}${divClass}`, style: Object.assign(Object.assign(Object.assign({}, divStyle), justify), cssVars), onClick: handleClick }, rest, { children: jsx(motion.div, { className: css.knob, layout: 'preserve-aspect' }) })));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export { Switch as S };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-0pkUdtrF.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
4
|
+
import { useTheme } from '../hooks/useTheme.js';
|
|
5
|
+
import '../theme/colors.js';
|
|
6
|
+
import '../hooks/useWindow.js';
|
|
7
|
+
import { B as Badge } from './Badge-PPf5Uvw3.js';
|
|
8
|
+
import { I as Icon } from './_types-BaYeLEWK.js';
|
|
9
|
+
import { I as IconButton } from './IconButton-CguHGkBM.js';
|
|
10
|
+
import { T as ToolTipType } from './sharedTypes-BfZzG1KX.js';
|
|
11
|
+
import { s as styleInject } from './style-inject.es-tgCJW-Cu.js';
|
|
12
|
+
|
|
13
|
+
var css_248z = ".flexBox-module_row__PWxbe {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowBetween__27lKK {\n\tdisplay: flex;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowStart__nJZnW {\n\tdisplay: flex;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowEnd__dHcOU {\n\tdisplay: flex;\n\tjustify-content: flex-end;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_column__MP2Xd {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStart__Kg8cV {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: flex-start;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStartCenter__zcmtk {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnBetween__157yI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnEnd__u2nwI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-end;\n\talign-items: flex-end;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.type-module_body-xs-regular__QWEzl {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-medium__FxEAv {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-bold__rf7AV {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.25px;\n}.type-module_body-s-regular__8-FO- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-medium__qyYq- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-bold__7GQ5Z {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-m-regular__Qtp5G {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-medium__Ieh9K {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-bold__0lZ3I {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-l-regular__Ar4d3 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-medium__6tV1n {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-bold__I8Q1v {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_heading-s-bold__QFgN8 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-s-medium__jGIb2 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-bold__tdBSi {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-medium__-7Uyu {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-medium__8hGYF {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-bold__Cryjg {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}\n\n.TabBar-module_wrapper__z8Cvg {\n\tgap: var(--tab-bar-gap);\n\tborder-bottom: var(--tab-bar-border-bottom) solid var(--core-outline-primary);\n\theight: var(--tab-bar-height);\n\twidth: var(--tab-bar-width);\n\tcursor: pointer;\n}\n\n.TabBar-module_option__Og-E4 {\n\tgap: var(--tab-bar-option-gap);\n\tcolor: var(--tab-bar-option-color);\n\tpadding: var(--tab-bar-option-padding) !important;\n\theight: 100%;\n\twidth: var(--tab-bar-option-width);\n\tflex: var(--tab-bar-option-flex);\n\twhite-space: nowrap;\n\tbox-shadow: 0 var(--tab-bar-option-border) 0 0 var(--core-text-special);\n\tcursor: var(--tab-bar-option-cursor);\n\t-webkit-user-select: none;\n\tuser-select: none;\n}\n\n.TabBar-module_icon__LU5Rp {\n\tmax-height: var(--tab-bar-icon-size);\n\tmin-height: var(--tab-bar-icon-size);\n\tmax-width: var(--tab-bar-icon-size);\n\tmin-width: var(--tab-bar-icon-size);\n}\n\n.TabBar-module_close__ytzs5 {\n\theight: 100%;\n\tpadding: var(--tab-bar-close-padding) !important;\n\tborder-left: 1px solid var(--core-outline-primary);\n\twidth: min-content;\n}\n";
|
|
14
|
+
var css = {"wrapper":"TabBar-module_wrapper__z8Cvg flexBox-module_rowStart__nJZnW","option":"TabBar-module_option__Og-E4 flexBox-module_row__PWxbe type-module_body-m-regular__Qtp5G","icon":"TabBar-module_icon__LU5Rp flexBox-module_row__PWxbe","close":"TabBar-module_close__ytzs5 flexBox-module_row__PWxbe"};
|
|
15
|
+
styleInject(css_248z);
|
|
16
|
+
|
|
17
|
+
const placeholderOptions = [
|
|
18
|
+
{ name: 'Option 1', value: 'Option 1', icon: null },
|
|
19
|
+
{ name: 'Option 2', value: 'Option 2', icon: 'wallet' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const TabBar = React.memo((props) => {
|
|
23
|
+
const { options = placeholderOptions, selected = 0, border = true, underline = true, height = '100%', width = '100%', tabWidth = 'distribute', padding = 8, iconSize = 20, iconGap = 8, tabGap = 0, disabled = false, hasClose = false, closeWidth = 'auto', selectedValue = null, onChange = () => null, onTabChange = () => null, onClose = () => null, onToolTip = () => null } = props, divAttributes = __rest(props, ["options", "selected", "border", "underline", "height", "width", "tabWidth", "padding", "iconSize", "iconGap", "tabGap", "disabled", "hasClose", "closeWidth", "selectedValue", "onChange", "onTabChange", "onClose", "onToolTip"]);
|
|
24
|
+
const { id: divId, className, style } = divAttributes, rest = __rest(divAttributes, ["id", "className", "style"]);
|
|
25
|
+
const divStyle = style !== null && style !== void 0 ? style : {};
|
|
26
|
+
const divClass = className ? ` ${className}` : '';
|
|
27
|
+
const [index, setIndex] = useState(selected);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
let selectedIndex = 0;
|
|
30
|
+
if (selectedValue && options) {
|
|
31
|
+
selectedIndex = options.findIndex((option) => option.value === selectedValue);
|
|
32
|
+
setIndex(selectedIndex === -1 ? selected : selectedIndex);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
setIndex(selected);
|
|
36
|
+
}
|
|
37
|
+
}, [selected, selectedValue, options]);
|
|
38
|
+
// memo handleClick
|
|
39
|
+
const handleClick = useCallback((i) => {
|
|
40
|
+
setIndex(i);
|
|
41
|
+
onChange(i);
|
|
42
|
+
onTabChange(options[i]);
|
|
43
|
+
}, [onChange, onTabChange, options]);
|
|
44
|
+
// memo handleOptionClick
|
|
45
|
+
const handleOptionClick = useCallback((i) => {
|
|
46
|
+
onToolTip(null);
|
|
47
|
+
handleClick(i);
|
|
48
|
+
}, [onToolTip, handleClick]);
|
|
49
|
+
// memo rendered options
|
|
50
|
+
const renderedOptions = useMemo(() => options.map((option, i) => (jsx(Option, { label: option.name, value: i, showToolTip: option.toolTip, selected: i === index, padding: padding, icon: option.icon, iconSize: iconSize, iconGap: iconGap, disabled: disabled, count: option.count, onClick: handleOptionClick, onToolTip: onToolTip, underline: underline, tabWidth: tabWidth }, `${i}_option_${option.name}`))), [
|
|
51
|
+
options,
|
|
52
|
+
index,
|
|
53
|
+
padding,
|
|
54
|
+
iconSize,
|
|
55
|
+
iconGap,
|
|
56
|
+
disabled,
|
|
57
|
+
underline,
|
|
58
|
+
tabWidth,
|
|
59
|
+
onToolTip,
|
|
60
|
+
handleOptionClick,
|
|
61
|
+
]);
|
|
62
|
+
const setStyle = useCallback((value) => {
|
|
63
|
+
if (typeof value === 'string')
|
|
64
|
+
return value;
|
|
65
|
+
return `${value}px`;
|
|
66
|
+
}, []);
|
|
67
|
+
const cssVars = useMemo(() => {
|
|
68
|
+
return {
|
|
69
|
+
'--tab-bar-gap': `${tabGap}px`,
|
|
70
|
+
'--tab-bar-height': `${setStyle(height)}px`,
|
|
71
|
+
'--tab-bar-width': setStyle(width),
|
|
72
|
+
'--tab-bar-border-bottom': `${border ? '1px' : '0'}`,
|
|
73
|
+
'--tab-bar-close-width': `${closeWidth}px`,
|
|
74
|
+
'--tab-bar-close-padding': padding ? `${padding}px` : '8px',
|
|
75
|
+
};
|
|
76
|
+
}, [tabGap, height, width, border, setStyle, closeWidth, padding]);
|
|
77
|
+
return (jsxs("div", Object.assign({ id: divId, className: `${css.wrapper}${divClass}`, style: Object.assign(Object.assign({}, divStyle), cssVars) }, rest, { children: [renderedOptions, hasClose && (jsx("div", { className: css.close, children: jsx(IconButton, { iconSize: iconSize - 4, frameSize: iconSize, toggle: false, hover: true, icon: 'x', onClick: onClose }) }))] })));
|
|
78
|
+
});
|
|
79
|
+
TabBar.displayName = 'TabBar';
|
|
80
|
+
const Option = React.memo((props) => {
|
|
81
|
+
const theme = useTheme();
|
|
82
|
+
const { label = 'Option', value = 0, icon = null, selected = false, onClick = () => null, onToolTip = () => null, padding = 8, iconSize = 20, iconGap = 6, disabled = false, showToolTip = null, underline = true, tabWidth = 'distribute', count = 0, } = props;
|
|
83
|
+
const ref = useRef(null);
|
|
84
|
+
// memo icon color
|
|
85
|
+
const strokeColor = useMemo(() => {
|
|
86
|
+
if (!disabled && selected)
|
|
87
|
+
return theme.current.colors['core-text-special'];
|
|
88
|
+
if (disabled)
|
|
89
|
+
return theme.current.colors['core-text-disabled'];
|
|
90
|
+
return theme.current.colors['core-text-primary'];
|
|
91
|
+
}, [disabled, selected, theme]);
|
|
92
|
+
// memo handleMouseOver
|
|
93
|
+
const handleMouseOver = useCallback((e) => {
|
|
94
|
+
onToolTip(null);
|
|
95
|
+
if (showToolTip && ref.current) {
|
|
96
|
+
const tip = {
|
|
97
|
+
type: ToolTipType.button,
|
|
98
|
+
payload: { label: showToolTip },
|
|
99
|
+
event: e,
|
|
100
|
+
ref,
|
|
101
|
+
};
|
|
102
|
+
onToolTip(tip);
|
|
103
|
+
}
|
|
104
|
+
}, [showToolTip, onToolTip]);
|
|
105
|
+
// memo handleMouseLeave
|
|
106
|
+
const handleMouseLeave = useCallback(() => {
|
|
107
|
+
if (showToolTip)
|
|
108
|
+
onToolTip(null);
|
|
109
|
+
}, [showToolTip, onToolTip]);
|
|
110
|
+
// memo color
|
|
111
|
+
const textColor = useMemo(() => {
|
|
112
|
+
if (disabled)
|
|
113
|
+
return 'var(--core-text-disabled)';
|
|
114
|
+
if (selected)
|
|
115
|
+
return 'var(--core-text-special)';
|
|
116
|
+
return 'var(--core-text-primary)';
|
|
117
|
+
}, [disabled, selected]);
|
|
118
|
+
// memo tab width
|
|
119
|
+
const setTabWidth = useMemo(() => {
|
|
120
|
+
if (tabWidth === 'min-content')
|
|
121
|
+
return 'min-content';
|
|
122
|
+
if (tabWidth === 'distribute')
|
|
123
|
+
return 'unset';
|
|
124
|
+
return `${tabWidth}px`;
|
|
125
|
+
}, [tabWidth]);
|
|
126
|
+
// memo flex tab
|
|
127
|
+
const setTabFlex = useMemo(() => {
|
|
128
|
+
if (tabWidth === 'distribute')
|
|
129
|
+
return '1';
|
|
130
|
+
return 'unset';
|
|
131
|
+
}, [tabWidth]);
|
|
132
|
+
// memo underline
|
|
133
|
+
const setUnderline = useMemo(() => {
|
|
134
|
+
if (selected && underline && !disabled)
|
|
135
|
+
return '1px';
|
|
136
|
+
return '0';
|
|
137
|
+
}, [underline, disabled, selected]);
|
|
138
|
+
const cssVars = useMemo(() => {
|
|
139
|
+
return {
|
|
140
|
+
'--tab-bar-option-border': setUnderline,
|
|
141
|
+
'--tab-bar-option-padding': `${padding}px`,
|
|
142
|
+
'--tab-bar-option-icon-size': `${iconSize}px`,
|
|
143
|
+
'--tab-bar-option-cursor': disabled ? 'default' : 'pointer',
|
|
144
|
+
'--tab-bar-option-gap': `${iconGap !== null && iconGap !== void 0 ? iconGap : 0}px`,
|
|
145
|
+
'--tab-bar-option-color': textColor,
|
|
146
|
+
'--tab-bar-option-width': setTabWidth,
|
|
147
|
+
'--tab-bar-option-flex': setTabFlex,
|
|
148
|
+
};
|
|
149
|
+
}, [
|
|
150
|
+
padding,
|
|
151
|
+
iconSize,
|
|
152
|
+
disabled,
|
|
153
|
+
textColor,
|
|
154
|
+
iconGap,
|
|
155
|
+
setTabFlex,
|
|
156
|
+
setTabWidth,
|
|
157
|
+
setUnderline,
|
|
158
|
+
]);
|
|
159
|
+
return (jsxs("div", { className: css.option, style: cssVars, ref: ref, "aria-selected": selected, onMouseEnter: handleMouseOver, onMouseLeave: handleMouseLeave, onClick: () => onClick(value), onKeyDown: () => onClick(value), children: [icon && (jsx("div", { className: css.icon, children: jsx(Icon, { name: icon, size: iconSize, strokeColor: strokeColor }) })), label, count !== 0 && (jsx(Badge, { variant: 'light', hideNull: false, count: count }))] }));
|
|
160
|
+
}, (prevProps, nextProps) => {
|
|
161
|
+
// Custom comparison for performance
|
|
162
|
+
return (prevProps.selected === nextProps.selected &&
|
|
163
|
+
prevProps.underline === nextProps.underline &&
|
|
164
|
+
prevProps.tabWidth === nextProps.tabWidth &&
|
|
165
|
+
prevProps.disabled === nextProps.disabled &&
|
|
166
|
+
prevProps.iconGap === nextProps.iconGap &&
|
|
167
|
+
prevProps.iconSize === nextProps.iconSize &&
|
|
168
|
+
prevProps.count === nextProps.count &&
|
|
169
|
+
prevProps.label === nextProps.label &&
|
|
170
|
+
prevProps.icon === nextProps.icon);
|
|
171
|
+
});
|
|
172
|
+
Option.displayName = 'TabOption';
|
|
173
|
+
|
|
174
|
+
export { TabBar as T };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-0pkUdtrF.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useState, useRef, useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { U as UIButton } from './UIButton-DKx-_O8h.js';
|
|
5
|
+
import { s as styleInject } from './style-inject.es-tgCJW-Cu.js';
|
|
6
|
+
|
|
7
|
+
var css_248z = ".flexBox-module_row__PWxbe {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowBetween__27lKK {\n\tdisplay: flex;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowStart__nJZnW {\n\tdisplay: flex;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowEnd__dHcOU {\n\tdisplay: flex;\n\tjustify-content: flex-end;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_column__MP2Xd {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStart__Kg8cV {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: flex-start;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStartCenter__zcmtk {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnBetween__157yI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnEnd__u2nwI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-end;\n\talign-items: flex-end;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.type-module_body-xs-regular__QWEzl {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-medium__FxEAv {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-bold__rf7AV {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.25px;\n}.type-module_body-s-regular__8-FO- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-medium__qyYq- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-bold__7GQ5Z {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-m-regular__Qtp5G {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-medium__Ieh9K {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-bold__0lZ3I {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-l-regular__Ar4d3 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-medium__6tV1n {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-bold__I8Q1v {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_heading-s-bold__QFgN8 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-s-medium__jGIb2 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-bold__tdBSi {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-medium__-7Uyu {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-medium__8hGYF {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-bold__Cryjg {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}\n\n.TextArea-module_wrapper__vgfIH {\n\tposition: relative;\n\tpadding: var(--ta-padding) !important;\n\twidth: var(--ta-width);\n\theight: auto;\n\tborder-radius: var(--ta-border-radius);\n\tbackground-color: var(--ta-bg-color);\n\tbox-shadow: 0 0 0 1px var(--ta-border-color);\n\ttransition: all 0.25s ease-in-out 0s;\n}\n\n.TextArea-module_textarea__eAcFn {\n\tborder: 0;\n\toutline: 0;\n\tpadding: 0 16px 0 0;\n\twidth: 100%;\n\theight: 100%;\n\tcolor: var(--core-text-primary);\n\tbackground-color: transparent;\n\tbox-sizing: border-box;\n\tresize: var(--ta-resize);\n\n\t&:disabled {\n\t\tcolor: var(--core-text-disabled);\n\t}\n\n\t&::placeholder {\n\t\tcolor: var(--core-text-disabled);\n\t}\n\n\toverflow-y: auto;\n\n\t&::-webkit-scrollbar {\n\t\tbackground-color: transparent;\n\t\twidth: 14px;\n\t}\n\n\t&::-webkit-scrollbar-track {\n\t\tbackground-color: transparent;\n\t}\n\n\t&::-webkit-scrollbar-thumb {\n\t\tbackground-color: var(--scroll-bar);\n\t\tborder-radius: 20px;\n\t\tborder: 4px solid var(--core-surface-primary);\n\t}\n\n\t&::-webkit-scrollbar-thumb:hover {\n\t\tbackground-color: var(--scroll-bar);\n\t\tborder-radius: 20px;\n\t\tborder: 4px solid var(--core-surface-primary);\n\t\tcursor: default;\n\t}\n}\n\n.TextArea-module_actions__hA93N {\n\twidth: 100%;\n\tmin-height: 30px;\n\tcolor: var(--core-text-disabled);\n\tgap: 16px;\n}\n\n.TextArea-module_option__DDx9A {\n\tgap: 4px;\n\twhite-space: nowrap;\n\tuser-select: none;\n\t-webkit-user-select: none;\n\tcursor: default;\n}\n\n.TextArea-module_send__SUUqB {\n\tposition: absolute;\n\tbottom: var(--ta-send-icon-offset-bottom);\n\tright: var(--ta-send-icon-offset-right);\n}\n\n.TextArea-module_s__53cFy {\n}\n\n.TextArea-module_m__TtgeD {\n}\n\n.TextArea-module_l__u69gT {\n}\n";
|
|
8
|
+
var css = {"wrapper":"TextArea-module_wrapper__vgfIH flexBox-module_columnStart__Kg8cV","textarea":"TextArea-module_textarea__eAcFn","send":"TextArea-module_send__SUUqB","s":"TextArea-module_s__53cFy type-module_body-s-regular__8-FO-","m":"TextArea-module_m__TtgeD type-module_body-m-regular__Qtp5G","l":"TextArea-module_l__u69gT type-module_body-l-regular__Ar4d3"};
|
|
9
|
+
styleInject(css_248z);
|
|
10
|
+
|
|
11
|
+
const TextArea = React.memo((props) => {
|
|
12
|
+
const { value = '', name = 'text_area', width = '100%', focused = false, placeholder = 'Enter text here...', rows = 6, border = false, borderRadius = 4, padding = '16px 4px 16px 16px', validate = false, resizable = true, hasSend = false, sendOffset = { bottom: 6, right: 6 }, sendSize = 36, returnSubmits = false, bgColor = undefined, minWidth = undefined, textSize = 'm', disabled = false, submitClears = true, onChange = () => null, onFocus = () => null, onBlur = () => null, onValidate = () => null, onSubmit = () => null, onKeyDown = () => null } = props, divAttributes = __rest(props, ["value", "name", "width", "focused", "placeholder", "rows", "border", "borderRadius", "padding", "validate", "resizable", "hasSend", "sendOffset", "sendSize", "returnSubmits", "bgColor", "minWidth", "textSize", "disabled", "submitClears", "onChange", "onFocus", "onBlur", "onValidate", "onSubmit", "onKeyDown"]);
|
|
13
|
+
const { id: divId, className, style } = divAttributes, rest = __rest(divAttributes, ["id", "className", "style"]);
|
|
14
|
+
const divStyle = style !== null && style !== void 0 ? style : {};
|
|
15
|
+
const divClass = className ? ` ${className}` : '';
|
|
16
|
+
const [isFocused, setIsFocused] = useState(focused);
|
|
17
|
+
const [invalid, setInvalid] = useState(false);
|
|
18
|
+
const [text, setText] = useState(value);
|
|
19
|
+
const [initiated, setInitiated] = useState(false);
|
|
20
|
+
const ref = useRef(null);
|
|
21
|
+
// update text area height
|
|
22
|
+
const handleResize = useCallback(() => {
|
|
23
|
+
if (!(ref === null || ref === void 0 ? void 0 : ref.current))
|
|
24
|
+
return;
|
|
25
|
+
ref.current.style.height = 'auto';
|
|
26
|
+
ref.current.style.height = `${ref.current.scrollHeight}px`;
|
|
27
|
+
}, []);
|
|
28
|
+
// validate content
|
|
29
|
+
const runValidation = useCallback((content) => {
|
|
30
|
+
let valid = true;
|
|
31
|
+
if (validate && content.length < 1)
|
|
32
|
+
valid = false;
|
|
33
|
+
if (!initiated)
|
|
34
|
+
valid = true;
|
|
35
|
+
onValidate(valid);
|
|
36
|
+
return !valid;
|
|
37
|
+
}, [initiated, onValidate, validate]);
|
|
38
|
+
// focus / blur field on prop change
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current) {
|
|
41
|
+
if (focused)
|
|
42
|
+
ref.current.focus();
|
|
43
|
+
else
|
|
44
|
+
ref.current.blur();
|
|
45
|
+
setIsFocused(focused);
|
|
46
|
+
}
|
|
47
|
+
}, [focused]);
|
|
48
|
+
// update value on prop change
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (value) {
|
|
51
|
+
setText(value);
|
|
52
|
+
setInvalid(runValidation(value));
|
|
53
|
+
}
|
|
54
|
+
}, [value, runValidation]);
|
|
55
|
+
// update height based on rows value
|
|
56
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: update heigt on rows change
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
handleResize();
|
|
59
|
+
}, [rows]);
|
|
60
|
+
// update value
|
|
61
|
+
const handleChange = useCallback((content) => {
|
|
62
|
+
onChange(content);
|
|
63
|
+
setText(content);
|
|
64
|
+
setInvalid(runValidation(content));
|
|
65
|
+
}, [onChange, runValidation]);
|
|
66
|
+
// set focus
|
|
67
|
+
const handleFocus = useCallback(() => {
|
|
68
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current)
|
|
69
|
+
ref.current.focus();
|
|
70
|
+
setInitiated(true);
|
|
71
|
+
setIsFocused(true);
|
|
72
|
+
onFocus();
|
|
73
|
+
}, [onFocus]);
|
|
74
|
+
// set blur
|
|
75
|
+
const handleBlur = useCallback((content) => {
|
|
76
|
+
handleChange(content);
|
|
77
|
+
setIsFocused(false);
|
|
78
|
+
onBlur();
|
|
79
|
+
}, [handleChange, onBlur]);
|
|
80
|
+
// trigger submit as needed
|
|
81
|
+
const handleSubmit = useCallback((e) => {
|
|
82
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
83
|
+
handleFocus();
|
|
84
|
+
onSubmit(text);
|
|
85
|
+
if (submitClears)
|
|
86
|
+
setText('');
|
|
87
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current)
|
|
88
|
+
ref.current.value = '';
|
|
89
|
+
handleResize();
|
|
90
|
+
}, [handleFocus, onSubmit, text, submitClears, handleResize]);
|
|
91
|
+
// handle return key
|
|
92
|
+
const handleKeyDownWrapper = useCallback((e) => {
|
|
93
|
+
if (returnSubmits && e.key === 'Enter') {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
handleSubmit(undefined);
|
|
97
|
+
}
|
|
98
|
+
onKeyDown(e);
|
|
99
|
+
}, [returnSubmits, handleSubmit, onKeyDown]);
|
|
100
|
+
// set style value
|
|
101
|
+
const setStyleValue = useCallback((value) => {
|
|
102
|
+
if (typeof value === 'string')
|
|
103
|
+
return value;
|
|
104
|
+
return `${value}px`;
|
|
105
|
+
}, []);
|
|
106
|
+
// memo border color
|
|
107
|
+
const setBorderColor = useMemo(() => {
|
|
108
|
+
if (isFocused)
|
|
109
|
+
return 'var(--core-link-primary)';
|
|
110
|
+
if (validate && invalid)
|
|
111
|
+
return 'var(--feedback-warning)';
|
|
112
|
+
return border ? 'var(--core-outline-primary)' : 'transparent';
|
|
113
|
+
}, [isFocused, invalid, validate, border]);
|
|
114
|
+
// memo text size
|
|
115
|
+
const textClassName = useMemo(() => {
|
|
116
|
+
if (textSize === 'l')
|
|
117
|
+
return css.l;
|
|
118
|
+
if (textSize === 'm')
|
|
119
|
+
return css.m;
|
|
120
|
+
return css.s;
|
|
121
|
+
}, [textSize]);
|
|
122
|
+
// memo css vars
|
|
123
|
+
const cssVars = useMemo(() => {
|
|
124
|
+
return {
|
|
125
|
+
'--ta-border-radius': `${borderRadius}px`,
|
|
126
|
+
'--ta-width': `${setStyleValue(width)}`,
|
|
127
|
+
'--ta-min-width': minWidth ? `${minWidth}px` : 'unset',
|
|
128
|
+
'--ta-bg-color': bgColor !== null && bgColor !== void 0 ? bgColor : 'var(--core-surface-secondary)',
|
|
129
|
+
'--ta-border-color': setBorderColor,
|
|
130
|
+
'--ta-padding': `${setStyleValue(padding)}`,
|
|
131
|
+
'--ta-send-icon-offset-bottom': `${sendOffset.bottom}px`,
|
|
132
|
+
'--ta-send-icon-offset-right': `${sendOffset.right}px`,
|
|
133
|
+
'--ta-send-icon-size': `${sendSize}px`,
|
|
134
|
+
'--ta-resize': resizable ? 'vertical' : 'none',
|
|
135
|
+
};
|
|
136
|
+
}, [
|
|
137
|
+
width,
|
|
138
|
+
minWidth,
|
|
139
|
+
bgColor,
|
|
140
|
+
setBorderColor,
|
|
141
|
+
padding,
|
|
142
|
+
sendOffset,
|
|
143
|
+
sendSize,
|
|
144
|
+
setStyleValue,
|
|
145
|
+
borderRadius,
|
|
146
|
+
resizable,
|
|
147
|
+
]);
|
|
148
|
+
return (jsxs("div", Object.assign({ id: divId, className: `${css.wrapper}${divClass}`, style: Object.assign(Object.assign({}, divStyle), cssVars), onBlur: () => handleBlur(text), onFocus: () => handleFocus() }, rest, { children: [hasSend && (jsx("div", { className: css.send, onMouseDown: (e) => handleSubmit(e), children: jsx(UIButton, { iconLeft: 'arrow up', size: 'medium', variant: 'solid', round: true }) })), jsx("textarea", { className: `${css.textarea} ${textClassName}`, ref: ref, name: name, value: text, placeholder: placeholder, rows: rows, disabled: disabled, onChange: (e) => handleChange(e.target.value), onInput: () => handleResize(), onKeyDown: (e) => handleKeyDownWrapper(e) })] })));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export { TextArea as T };
|