@os-design/core 1.0.129 → 1.0.132
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/Button/index.js.map +1 -1
- package/dist/cjs/Input/index.js +3 -1
- package/dist/cjs/Input/index.js.map +1 -1
- package/dist/cjs/Modal/index.js +11 -3
- package/dist/cjs/Modal/index.js.map +1 -1
- package/dist/cjs/RadioGroup/index.js +18 -5
- package/dist/cjs/RadioGroup/index.js.map +1 -1
- package/dist/esm/Button/index.js.map +1 -1
- package/dist/esm/Input/index.js +2 -0
- package/dist/esm/Input/index.js.map +1 -1
- package/dist/esm/Modal/index.js +9 -3
- package/dist/esm/Modal/index.js.map +1 -1
- package/dist/esm/RadioGroup/index.js +23 -8
- package/dist/esm/RadioGroup/index.js.map +1 -1
- package/dist/types/Input/index.d.ts.map +1 -1
- package/dist/types/Modal/index.d.ts.map +1 -1
- package/dist/types/RadioGroup/index.d.ts +1 -0
- package/dist/types/RadioGroup/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Button/index.tsx"],"names":["hoverStyles","p","disabled","css","colors","bgHover","primaryStyles","btnType","text","bg","ghostStyles","outlineStyles","wideDefaultStyles","wide","m","max","xxs","wideAlwaysStyles","disabledStyles","StyledButton","resetButtonStyles","theme","borderRadius","buttonHeight","buttonPaddingHorizontal","sizeStyles","Button","ref","type","danger","left","right","loading","size","children","onMouseDown","rest","buttonColors","loadingColors","e","preventDefault","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AA0DA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,0LAK0B,kBAAIF,CAAC,CAACG,MAAF,CAASC,OAAb,CAL1B,CADkB;AAAA,CAApB;;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A,OAAO,EAAEV,IADX;AAEE,IAAA,MAAM,EAAES,YAFV;AAGE,IAAA,IAAI,EAAExB,IAHR;AAIE,IAAA,OAAO,EAAEmB,OAJX;AAKE,IAAA,QAAQ,EAAE9B,QAAQ,IAAI8B,OALxB;AAME,IAAA,IAAI,EAAEC,IANR;AAOE,IAAA,WAAW,EAAE,qBAACM,CAAD,EAAO;AAClBJ,MAAAA,YAAW,CAACI,CAAD,CAAX;;AACAA,MAAAA,CAAC,CAACC,cAAF;AACD,KAVH;AAWE,iBAAWR;AAXb,KAYMI,IAZN;AAaE,IAAA,GAAG,EAAET;AAbP,mBAeE,gCAAC,yBAAD;AACE,IAAA,IAAI,EAAEG,IADR;AAEE,IAAA,KAAK,EAAEC,KAFT;AAGE,IAAA,OAAO,EAAEC,OAHX;AAIE,IAAA,aAAa,EAAEM;AAJjB,KAMGJ,QANH,CAfF,CADF;AA0BD,CAjDY,CAAf;AAoDAR,MAAM,CAACe,WAAP,GAAqB,QAArB;eAEef,M","sourcesContent":["import React, { forwardRef } from 'react';\nimport styled from '@emotion/styled';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps } from '@os-design/utils';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { m } from '@os-design/media';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\nimport ButtonContent from './ButtonContent';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button, LinkButton\nexport interface BaseButtonProps extends WithSize {\n /**\n * Type of button styles.\n * @default primary\n */\n type?: 'primary' | 'outline' | 'ghost';\n /**\n * Sets the danger styles.\n * @default false\n */\n danger?: boolean;\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Whether the button has full width.\n * Possible values:\n * `default` – the button has full width if the screen width is less than xs;\n * `always` – the button always has full width;\n * `never` – the button never has full width
|
|
1
|
+
{"version":3,"sources":["../../../src/Button/index.tsx"],"names":["hoverStyles","p","disabled","css","colors","bgHover","primaryStyles","btnType","text","bg","ghostStyles","outlineStyles","wideDefaultStyles","wide","m","max","xxs","wideAlwaysStyles","disabledStyles","StyledButton","resetButtonStyles","theme","borderRadius","buttonHeight","buttonPaddingHorizontal","sizeStyles","Button","ref","type","danger","left","right","loading","size","children","onMouseDown","rest","buttonColors","loadingColors","e","preventDefault","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AA0DA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,0LAK0B,kBAAIF,CAAC,CAACG,MAAF,CAASC,OAAb,CAL1B,CADkB;AAAA,CAApB;;AAWA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACL,CAAD;AAAA,SACpBA,CAAC,CAACM,OAAF,KAAc,SAAd,QACAJ,WADA,uIAEW,kBAAIF,CAAC,CAACG,MAAF,CAASI,IAAb,CAFX,EAGsB,kBAAIP,CAAC,CAACG,MAAF,CAASK,EAAb,CAHtB,EAIIT,WAAW,CAACC,CAAD,CAJf,CADoB;AAAA,CAAtB;;AAQA,IAAMS,WAAW,GAAG,SAAdA,WAAc,CAACT,CAAD;AAAA,SAClBA,CAAC,CAACM,OAAF,KAAc,OAAd,QACAJ,WADA,8IAEW,kBAAIF,CAAC,CAACG,MAAF,CAASI,IAAb,CAFX,EAIIR,WAAW,CAACC,CAAD,CAJf,CADkB;AAAA,CAApB;;AAQA,IAAMU,aAAa,GAAG,SAAhBA,aAAgB,CAACV,CAAD;AAAA,SACpBA,CAAC,CAACM,OAAF,KAAc,SAAd,QACAJ,WADA,mLAEW,kBAAIF,CAAC,CAACG,MAAF,CAASI,IAAb,CA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["import React, { forwardRef } from 'react';\nimport styled from '@emotion/styled';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps } from '@os-design/utils';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { m } from '@os-design/media';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\nimport ButtonContent from './ButtonContent';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button, LinkButton\nexport interface BaseButtonProps extends WithSize {\n /**\n * Type of button styles.\n * @default primary\n */\n type?: 'primary' | 'outline' | 'ghost';\n /**\n * Sets the danger styles.\n * @default false\n */\n danger?: boolean;\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Whether the button has full width.\n * Possible values:\n * `default` – the button has full width if the screen width is less than xs;\n * `always` – the button always has full width;\n * `never` – the button never has full width.\n * @default default\n */\n wide?: 'default' | 'always' | 'never';\n /**\n * Shows the loading status and disables the button.\n * @default false\n */\n loading?: boolean;\n /**\n * Whether the button is disabled.\n * @default false\n */\n disabled?: boolean;\n}\n\nexport type ButtonProps = JsxButtonProps & BaseButtonProps;\n\ninterface StyledButtonProps\n extends Pick<ButtonProps, 'wide' | 'loading' | 'disabled' | 'size'> {\n btnType: ButtonProps['type'];\n colors: ButtonColors;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover,\n &:focus {\n background-color: ${clr(p.colors.bgHover)};\n }\n }\n `;\n\nconst primaryStyles = (p) =>\n p.btnType === 'primary' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: ${clr(p.colors.bg)};\n ${hoverStyles(p)};\n `;\n\nconst ghostStyles = (p) =>\n p.btnType === 'ghost' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: transparent;\n ${hoverStyles(p)};\n `;\n\nconst outlineStyles = (p) =>\n p.btnType === 'outline' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: transparent;\n border: 1px solid currentColor;\n ${hoverStyles(p)};\n `;\n\nconst wideDefaultStyles = (p) =>\n p.wide === 'default' &&\n css`\n ${m.max.xxs} {\n width: 100%;\n }\n `;\n\nconst wideAlwaysStyles = (p) =>\n p.wide === 'always' &&\n css`\n width: 100%;\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n `;\n\nexport const StyledButton = styled(\n 'button',\n omitEmotionProps('btnType', 'colors', 'wide', 'loading', 'size')\n)<StyledButtonProps>`\n ${resetButtonStyles};\n position: relative; // Because LoadingContainer has an absolute position\n cursor: pointer;\n user-select: none;\n box-sizing: border-box; // Important for LinkButton\n\n // Disable multiline\n white-space: nowrap;\n overflow: hidden;\n\n border-radius: ${(p) => p.theme.borderRadius}em;\n height: ${(p) => p.theme.buttonHeight}em;\n padding: 0 ${(p) => p.theme.buttonPaddingHorizontal}em;\n\n // Do not set inline-flex, otherwise the mobile safari cuts off\n // the bottom border of the button (tested in iPhone 6)\n display: flex;\n justify-content: center;\n align-items: center;\n\n font-weight: 500;\n line-height: 1;\n\n ${primaryStyles};\n ${outlineStyles};\n ${ghostStyles};\n\n ${wideDefaultStyles};\n ${wideAlwaysStyles};\n\n ${disabledStyles};\n\n ${sizeStyles};\n ${transitionStyles('background-color', 'color')};\n`;\n\n/**\n * Used to trigger the corresponding business logic.\n */\nconst Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n type = 'primary',\n danger = false,\n left,\n right,\n wide = 'default',\n loading = false,\n disabled = false,\n size,\n children,\n onMouseDown = () => {},\n ...rest\n },\n ref\n ) => {\n const { buttonColors, loadingColors } = useButtonColors({\n type,\n danger,\n disabled,\n });\n\n return (\n <StyledButton\n btnType={type}\n colors={buttonColors}\n wide={wide}\n loading={loading}\n disabled={disabled || loading}\n size={size}\n onMouseDown={(e) => {\n onMouseDown(e);\n e.preventDefault();\n }}\n aria-busy={loading}\n {...rest}\n ref={ref}\n >\n <ButtonContent\n left={left}\n right={right}\n loading={loading}\n loadingColors={loadingColors}\n >\n {children}\n </ButtonContent>\n </StyledButton>\n );\n }\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"file":"index.js"}
|
package/dist/cjs/Input/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var _icons = require("@os-design/icons");
|
|
|
23
23
|
|
|
24
24
|
var _getFocusableElements = _interopRequireDefault(require("./utils/getFocusableElements"));
|
|
25
25
|
|
|
26
|
-
var _excluded = ["type", "left", "leftHasPadding", "right", "rightHasPadding", "disabled", "loading", "containerRef", "containerProps", "size", "onChange"];
|
|
26
|
+
var _excluded = ["type", "left", "leftHasPadding", "right", "rightHasPadding", "disabled", "loading", "containerRef", "containerProps", "size", "value", "onChange"];
|
|
27
27
|
|
|
28
28
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
|
|
29
29
|
|
|
@@ -126,6 +126,7 @@ var Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
126
126
|
_ref$containerProps = _ref.containerProps,
|
|
127
127
|
containerProps = _ref$containerProps === void 0 ? {} : _ref$containerProps,
|
|
128
128
|
size = _ref.size,
|
|
129
|
+
value = _ref.value,
|
|
129
130
|
_ref$onChange = _ref.onChange,
|
|
130
131
|
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
131
132
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -180,6 +181,7 @@ var Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
180
181
|
disabled: disabled,
|
|
181
182
|
hasLeft: !!left,
|
|
182
183
|
hasRight: !!right,
|
|
184
|
+
value: value || '',
|
|
183
185
|
onChange: function onChange(e) {
|
|
184
186
|
return _onChange(e.target.value, e);
|
|
185
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Input/index.tsx"],"names":["hoverStyles","p","disabled","css","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","resetFocusStyles","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","sizeStyles","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","ref","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","onChange","rest","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","value","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,sKAIsB,kBAAIF,CAAC,CAACG,KAAF,CAAQC,qBAAZ,CAJtB,CADkB;AAAA,CAApB;;AAUA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACL,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,2KAGoB,kBAAIF,CAAC,CAACG,KAAF,CAAQG,qBAAZ,CAHpB,EAI+B,kBAAIN,CAAC,CAACG,KAAF,CAAQI,qBAAZ,CAJ/B,CADkB;AAAA,CAApB;;AASA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACR,CAAD;AAAA,SACrBA,CAAC,CAACC,QAAF,QACAC,WADA,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A,GAAG,EAAEX;AAPP,KAzCF,EAmDGc,UAAU,iBACT,gCAAC,uBAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,gCAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CApDJ,CADF;AA6DD,CA5FW,CAAd;AA+FAf,KAAK,CAACkC,WAAN,GAAoB,OAApB;eAEelC,K","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/Input/index.tsx"],"names":["hoverStyles","p","disabled","css","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","resetFocusStyles","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","sizeStyles","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","ref","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","value","onChange","rest","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,sKAIsB,kBAAIF,CAAC,CAACG,KAAF,CAAQC,qBAAZ,CAJtB,CADkB;AAAA,CAApB;;AAUA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACL,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,2KAGoB,kBAAIF,CAAC,CAACG,KAAF,CAAQG,qBAAZ,CAHpB,EAI+B,kBAAIN,CAAC,CAACG,KAAF,CAAQI,qBAAZ,CAJ/B,CADkB;AAAA,CAApB;;AASA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACR,CAAD;AAAA,SACrBA,CAAC,CAACC,QAAF,QACAC,WADA,uSAGW,kBAAIF,CAAC,CAACG,KAAF,CAAQM,sBAAZ,CAHX,EAIsB,kBAAIT,CAAC,CAACG,KAAF,CAAQO,oBAAZ,CAJtB,EAKkB,kBAAIV,CAAC,CAACG,KAAF,CAAQQ,wBAAZ,CALlB,EAWe,kBAAIX,CAAC,CAACG,KAAF,CAAQS,6BAAZ,CAXf,CADqB;AAAA,CAAvB;;AAkBO,IAAMC,cAAc,GAAG,wBAC5B,KAD4B,EAE5B,6BAAiB,UAAjB,EAA6B,MAA7B,CAF4B,CAAH,qTAIvBC,wBAJuB,EAQf,UAACd,CAAD;AAAA,SAAOA,CAAC,CAACG,KAAF,CAAQY,UAAf;AAAA,CARe,EAUL,UAACf,CAAD;AAAA,SAAO,kBAAIA,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,EAAD;AAAA,iBAAQA,EAAE,KAAKjB,iBAAiB,CAACM,OAAjC;AAAA,SAD0B,CAA5B;AAGA,YAAIS,mBAAmB,KAAK,CAA5B,EAA+B;AAC/B,YAAMG,2BAA2B,GAC/BX,iBAAiB,CAACQ,mBAAmB,GAAG,CAAvB,CADnB;AAEAG,QAAAA,2BAA2B,CAACV,KAA5B;AACD;AACF,KA/BH;AAgCE,IAAA,GAAG,EAAEP;AAhCP,KAiCMN,cAjCN,GAmCGN,IAAI,iBACH,gCAAC,uBAAD;AAAgB,IAAA,SAAS,EAAE;AAAE8B,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,gCAAC,SAAD;AAAW,IAAA,UAAU,EAAE7B;AAAvB,KAAwCD,IAAxC,CADF,CApCJ,eAyCE,gCAAC,WAAD;AACE,IAAA,IAAI,EAAED,IADR;AAEE,IAAA,QAAQ,EAAEnC,QAFZ;AAGE,IAAA,OAAO,EAAE,CAAC,CAACoC,IAHb;AAIE,IAAA,QAAQ,EAAE,CAAC,CAACE,KAJd;AAKE,IAAA,KAAK,EAAEM,KAAK,IAAI,EALlB;AAME,IAAA,QAAQ,EAAE,kBAACO,CAAD;AAAA,aAAON,SAAQ,CAACM,CAAC,CAACC,MAAF,CAASR,KAAV,EAAiBO,CAAjB,CAAf;AAAA;AANZ,KAOML,IAPN;AAQE,IAAA,GAAG,EAAEZ;AARP,KAzCF,EAoDGe,UAAU,iBACT,gCAAC,uBAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,gCAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CArDJ,CADF;AA8DD,CA9FW,CAAd;AAiGAhB,KAAK,CAACkC,WAAN,GAAoB,OAApB;eAEelC,K","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n value,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n value={value || ''}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
|
package/dist/cjs/Modal/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var _Button = _interopRequireDefault(require("../Button"));
|
|
|
31
31
|
|
|
32
32
|
var _defaultLocale = _interopRequireDefault(require("./utils/defaultLocale"));
|
|
33
33
|
|
|
34
|
-
var _excluded = ["title", "okText", "okDanger", "okLoading", "okDisabled", "header", "footer", "visible", "locale", "onClose", "onOk", "size", "id", "children"];
|
|
34
|
+
var _excluded = ["title", "okText", "okDanger", "okLoading", "okDisabled", "header", "footer", "visible", "locale", "onClose", "onOk", "size", "id", "onClick", "children"];
|
|
35
35
|
|
|
36
36
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
37
37
|
|
|
@@ -163,6 +163,8 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
163
163
|
onOk = _ref.onOk,
|
|
164
164
|
size = _ref.size,
|
|
165
165
|
id = _ref.id,
|
|
166
|
+
_ref$onClick = _ref.onClick,
|
|
167
|
+
_onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
|
|
166
168
|
children = _ref.children,
|
|
167
169
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
168
170
|
|
|
@@ -173,7 +175,6 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
173
175
|
|
|
174
176
|
var mounted = (0, _utils.useClosable)(visible, theme.transitionDelay);
|
|
175
177
|
(0, _utils.useBodyScroll)(!visible);
|
|
176
|
-
(0, _utils.useClickOutside)(contentRef, onClose);
|
|
177
178
|
(0, _utils.useKeyPress)(typeof window !== 'undefined' ? window : undefined, 'Escape', onClose);
|
|
178
179
|
var titleId = (0, _react.useMemo)(function () {
|
|
179
180
|
return "modal-title-".concat(Math.random().toString(36).slice(2, 11));
|
|
@@ -184,11 +185,18 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
184
185
|
if (!mounted) return null;
|
|
185
186
|
return /*#__PURE__*/_react["default"].createElement(_portal["default"], null, /*#__PURE__*/_react["default"].createElement(ModalMask, {
|
|
186
187
|
visible: visible
|
|
187
|
-
}), /*#__PURE__*/_react["default"].createElement(Container,
|
|
188
|
+
}), /*#__PURE__*/_react["default"].createElement(Container, {
|
|
189
|
+
onClick: onClose
|
|
190
|
+
}, /*#__PURE__*/_react["default"].createElement(_reactFocusLock["default"], {
|
|
188
191
|
autoFocus: false
|
|
189
192
|
}, /*#__PURE__*/_react["default"].createElement(Content, {
|
|
190
193
|
visible: visible,
|
|
191
194
|
size: size,
|
|
195
|
+
onClick: function onClick(e) {
|
|
196
|
+
e.stopPropagation();
|
|
197
|
+
|
|
198
|
+
_onClick(e);
|
|
199
|
+
},
|
|
192
200
|
role: "dialog",
|
|
193
201
|
"aria-modal": true,
|
|
194
202
|
"aria-labelledby": header === undefined ? titleId : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Modal/index.tsx"],"names":["MODAL_CONTAINER_Z_INDEX","MODAL_BOX_SHADOW_SIZE_EM","maskFadeIn","keyframes","maskFadeOut","maskVisibleStyles","p","visible","css","theme","transitionDelay","maskInvisibleStyles","ModalMask","modalMaskColorBg","Container","styled","div","m","min","xs","contentFadeIn","contentFadeOut","contentFadeInXs","contentFadeOutXs","contentVisibleStyles","contentInvisibleStyles","Content","colorBg","colorText","modalColorBoxShadow","borderRadius","modalWidth","sizeStyles","Header","modalHeaderHeight","modalHeaderColorBorderBottom","modalBodyPaddingHorizontal","Math","max","buttonPaddingHorizontal","Title","sizes","large","ellipsisStyles","Body","modalBodyPaddingVertical","Footer","Modal","ref","title","okText","okDanger","okLoading","okDisabled","header","footer","locale","defaultLocale","onClose","onOk","size","id","children","rest","contentRef","mounted","window","undefined","titleId","random","toString","slice","bodyId","t","modalCloseButtonPaddingHorizontal","closeLabel","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAOA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAgEA,IAAMA,uBAAuB,GAAG,IAAhC;AACA,IAAMC,wBAAwB,GAAG,CAAjC;AAEA,IAAMC,UAAU,OAAGC,iBAAH,sHAAhB;AAKA,IAAMC,WAAW,OAAGD,iBAAH,wHAAjB;;AAKA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,CAAD;AAAA,SACxBA,CAAC,CAACC,OAAF,QACAC,WADA,mHAEeN,UAFf,EAE6BI,CAAC,CAACG,KAAF,CAAQC,eAFrC,CADwB;AAAA,CAA1B;;AAMA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACL,CAAD;AAAA,SAC1B,CAACA,CAAC,CAACC,OAAH,QACAC,WADA,mHAEeJ,WAFf,EAE8BE,CAAC,CAACG,KAAF,CAAQC,eAFtC,CAD0B;AAAA,CAA5B;;AAOO,IAAME,SAAS,GAAG,wBAAO,KAAP,EAAc,6BAAiB,SAAjB,CAAd,CAAH,kNAMA,UAACN,CAAD;AAAA,SAAO,kBAAIA,CAAC,CAACG,KAAF,CAAQI,gBAAZ,CAAP;AAAA,CANA,E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M,IAAA,EAAE,EAAEkB;AAAV,KAAsBT,IAAtB;AAA4B,IAAA,GAAG,EAAEf;AAAjC,MACGc,QADH,CAhCF,EAoCGP,MAAM,KAAKY,SAAX,gBACC,gCAAC,MAAD,qBACE,gCAAC,kBAAD;AACE,IAAA,MAAM,EAAEhB,QADV;AAEE,IAAA,OAAO,EAAEC,SAFX;AAGE,IAAA,QAAQ,EAAEC,UAHZ;AAIE,IAAA,OAAO,EAAEM;AAJX,KAMGT,MANH,CADF,CADD,GAYCK,MAhDJ,CADF,CADF,CAFF,CADF;AA4DD,CAvGW,CAAd;AA0GAR,KAAK,CAAC6B,WAAN,GAAoB,OAApB;eAEe7B,K","sourcesContent":["import React, { forwardRef, useMemo, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport styled from '@emotion/styled';\nimport {\n useBodyScroll,\n useClickOutside,\n useKeyPress,\n useClosable,\n omitEmotionProps,\n} from '@os-design/utils';\nimport {\n ellipsisStyles,\n enableScrollingStyles,\n sizeStyles,\n WithSize,\n} from '@os-design/styles';\nimport { m } from '@os-design/media';\nimport { css, keyframes } from '@emotion/react';\nimport { Close } from '@os-design/icons';\nimport { clr, ThemeOverrider, useTheme } from '@os-design/theming';\nimport Portal from '@os-design/portal';\nimport Button from '../Button';\nimport defaultLocale, { ModalLocale } from './utils/defaultLocale';\n\ntype JsxDivProps = Omit<JSX.IntrinsicElements['div'], 'ref'>;\nexport interface ModalProps extends JsxDivProps, WithSize {\n /**\n * The title of the modal.\n * @default undefined\n */\n title?: string;\n /**\n * The text of the OK button.\n * @default OK\n */\n okText?: string;\n /**\n * Sets the danger styles to the OK button.\n * @default false\n */\n okDanger?: boolean;\n /**\n * Whether the OK button is loading.\n * @default false\n */\n okLoading?: boolean;\n /**\n * Whether the OK button is disabled.\n * @default false\n */\n okDisabled?: boolean;\n /**\n * The header component.\n * Set as null if you don't need the default header.\n * @default undefined\n */\n header?: React.ReactNode;\n /**\n * The footer component.\n * Set as null if you don't need the default footer.\n * @default undefined\n */\n footer?: React.ReactNode;\n /**\n * Whether the modal is visible.\n * @default false\n */\n visible?: boolean;\n /**\n * The locale of the modal.\n * @default undefined\n */\n locale?: ModalLocale;\n /**\n * Specifies a callback that will be called when a user clicks the mask or\n * the close button. The callback should set the visible state to false.\n * @default undefined\n */\n onClose?: () => void;\n /**\n * Specifies a callback that will be called when a user clicks the OK button.\n * @default undefined\n */\n onOk?: () => void;\n}\n\nconst MODAL_CONTAINER_Z_INDEX = 1000;\nconst MODAL_BOX_SHADOW_SIZE_EM = 1;\n\nconst maskFadeIn = keyframes`\n from { opacity: 0; }\n to { opacity: 1; }\n`;\n\nconst maskFadeOut = keyframes`\n from { opacity: 1; }\n to { opacity: 0; }\n`;\n\nconst maskVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${maskFadeIn} ${p.theme.transitionDelay}ms forwards;\n `;\n\nconst maskInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${maskFadeOut} ${p.theme.transitionDelay}ms forwards;\n `;\n\ntype MaskProps = Pick<ModalProps, 'visible'>;\nexport const ModalMask = styled('div', omitEmotionProps('visible'))<MaskProps>`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n background-color: ${(p) => clr(p.theme.modalMaskColorBg)};\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n ${maskVisibleStyles};\n ${maskInvisibleStyles};\n`;\n\nconst Container = styled.div`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n\n ${m.min.xs} {\n ${enableScrollingStyles('y')};\n }\n`;\n\nconst contentFadeIn = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n`;\n\nconst contentFadeOut = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentFadeInXs = keyframes`\n from { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(6em); }\n`;\n\nconst contentFadeOutXs = keyframes`\n from { transform: translateY(6em); }\n to { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${contentFadeIn} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeInXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\nconst contentInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${contentFadeOut} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeOutXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\ntype ContentProps = Pick<ModalProps, 'visible' | 'size'>;\nconst Content = styled(\n 'div',\n omitEmotionProps('visible', 'size')\n)<ContentProps>`\n position: absolute;\n display: flex;\n flex-direction: column;\n padding-bottom: env(safe-area-inset-bottom);\n\n background-color: ${(p) => clr(p.theme.colorBg)};\n color: ${(p) => clr(p.theme.colorText)};\n box-shadow: 0 0 ${MODAL_BOX_SHADOW_SIZE_EM}em\n ${(p) => clr(p.theme.modalColorBoxShadow)};\n\n width: 100%;\n max-height: 100%;\n border-radius: ${(p) => p.theme.borderRadius}em\n ${(p) => p.theme.borderRadius}em 0 0;\n\n ${m.min.xs} {\n width: ${(p) => p.theme.modalWidth}em;\n max-height: unset;\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n left: 50%;\n margin-left: ${(p) => -p.theme.modalWidth / 2}em;\n }\n\n ${contentVisibleStyles};\n ${contentInvisibleStyles}\n ${sizeStyles};\n`;\n\nconst Header = styled.div`\n flex-shrink: 0;\n height: ${(p) => p.theme.modalHeaderHeight}em;\n border-bottom: 1px solid ${(p) => clr(p.theme.modalHeaderColorBorderBottom)};\n box-sizing: border-box;\n\n display: flex;\n align-items: center;\n\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n\n ${m.min.xs} {\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n }\n`;\n\nconst Title = styled.div`\n flex: 1;\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n ${ellipsisStyles};\n`;\n\nconst Body = styled.div`\n flex-grow: 1;\n\n padding: ${(p) => p.theme.modalBodyPaddingVertical[0]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n\n ${m.min.xs} {\n padding: ${(p) => p.theme.modalBodyPaddingVertical[1]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n }\n\n ${enableScrollingStyles('y')};\n`;\n\nconst Footer = styled.div`\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em\n ${(p) => p.theme.modalBodyPaddingVertical[0]}em;\n\n ${m.min.xs} {\n display: flex;\n justify-content: flex-end;\n align-items: center;\n\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em\n ${(p) => p.theme.modalBodyPaddingVertical[1]}em;\n }\n`;\n\n/**\n * The base pop-up window.\n */\nconst Modal = forwardRef<HTMLDivElement, ModalProps>(\n (\n {\n title,\n okText = 'OK',\n okDanger = false,\n okLoading = false,\n okDisabled = false,\n header,\n footer,\n visible = false,\n locale = defaultLocale,\n onClose = () => {},\n onOk,\n size,\n id,\n children,\n ...rest\n },\n ref\n ) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const { theme } = useTheme();\n const mounted = useClosable(visible, theme.transitionDelay);\n useBodyScroll(!visible);\n useClickOutside(contentRef, onClose);\n useKeyPress(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'Escape',\n onClose\n );\n\n const titleId = useMemo(\n () => `modal-title-${Math.random().toString(36).slice(2, 11)}`,\n []\n );\n const bodyId = useMemo(\n () => id || `modal-body-${Math.random().toString(36).slice(2, 11)}`,\n [id]\n );\n\n if (!mounted) return null;\n\n return (\n <Portal>\n <ModalMask visible={visible} />\n <Container>\n <FocusLock autoFocus={false}>\n <Content\n visible={visible}\n size={size}\n role='dialog'\n aria-modal\n aria-labelledby={header === undefined ? titleId : undefined}\n aria-describedby={bodyId}\n ref={contentRef}\n >\n {header === undefined ? (\n <ThemeOverrider\n overrides={(t) => ({\n buttonPaddingHorizontal:\n t.modalCloseButtonPaddingHorizontal,\n })}\n >\n <Header>\n <Title id={titleId}>{title}</Title>\n <Button\n type='ghost'\n wide='never'\n onClick={onClose}\n aria-label={locale.closeLabel}\n >\n <Close />\n </Button>\n </Header>\n </ThemeOverrider>\n ) : (\n header\n )}\n\n <Body id={bodyId} {...rest} ref={ref}>\n {children}\n </Body>\n\n {footer === undefined ? (\n <Footer>\n <Button\n danger={okDanger}\n loading={okLoading}\n disabled={okDisabled}\n onClick={onOk}\n >\n {okText}\n </Button>\n </Footer>\n ) : (\n footer\n )}\n </Content>\n </FocusLock>\n </Container>\n </Portal>\n );\n }\n);\n\nModal.displayName = 'Modal';\n\nexport default Modal;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/Modal/index.tsx"],"names":["MODAL_CONTAINER_Z_INDEX","MODAL_BOX_SHADOW_SIZE_EM","maskFadeIn","keyframes","maskFadeOut","maskVisibleStyles","p","visible","css","theme","transitionDelay","maskInvisibleStyles","ModalMask","modalMaskColorBg","Container","styled","div","m","min","xs","contentFadeIn","contentFadeOut","contentFadeInXs","contentFadeOutXs","contentVisibleStyles","contentInvisibleStyles","Content","colorBg","colorText","modalColorBoxShadow","borderRadius","modalWidth","sizeStyles","Header","modalHeaderHeight","modalHeaderColorBorderBottom","modalBodyPaddingHorizontal","Math","max","buttonPaddingHorizontal","Title","sizes","large","ellipsisStyles","Body","modalBodyPaddingVertical","Footer","Modal","ref","title","okText","okDanger","okLoading","okDisabled","header","footer","locale","defaultLocale","onClose","onOk","size","id","onClick","children","rest","contentRef","mounted","window","undefined","titleId","random","toString","slice","bodyId","e","stopPropagation","t","modalCloseButtonPaddingHorizontal","closeLabel","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAgEA,IAAMA,uBAAuB,GAAG,IAAhC;AACA,IAAMC,wBAAwB,GAAG,CAAjC;AAEA,IAAMC,UAAU,OAAGC,iBAAH,sHAAhB;AAKA,IAAMC,WAAW,OAAGD,iBAAH,wHAAjB;;AAKA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,CAAD;AAAA,SACxBA,CAAC,CAACC,OAAF,QACAC,WADA,mHAEeN,UAFf,EAE6BI,CAAC,CAACG,KAAF,CAAQC,eAFrC,CADwB;AAAA,CAA1B;;AAMA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACL,CAAD;AAAA,SAC1B,CAACA,CAAC,CAACC,OAAH,QACAC,WADA,mHAEeJ,WAFf,EAE8BE,CAAC,CAACG,KAAF,CAAQC,eAFtC,CAD0B;AAAA,CAA5B;;AAOO,IAAME,SAAS,GAAG,wBAAO,KAAP,EAAc,6BAAiB,SAAjB,CAAd,CAAH,kNAMA,UAACN,CAAD;AAAA,SAAO,kBAAIA,CAAC,CAACG,KAAF,CAAQI,gBAAZ,CAAP;AAAA,CANA,EAOTb,uBAPS,EAQlBK,iBARkB,EASlBM,mBATkB,CAAf;;;AAYP,IAAMG,SAAS,GAAGC,mBAAOC,GAAV,iMAMFhB,uBANE,EAQXiB,SAAEC,GAAF,CAAMC,EARK,EAST,mCAAsB,GAAtB,CATS,CAAf;;AAaA,I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CAAC,IAAD;AAAM,IAAA,EAAE,EAAEmB;AAAV,KAAsBT,IAAtB;AAA4B,IAAA,GAAG,EAAEhB;AAAjC,MACGe,QADH,CApCF,EAwCGR,MAAM,KAAKa,SAAX,gBACC,gCAAC,MAAD,qBACE,gCAAC,kBAAD;AACE,IAAA,MAAM,EAAEjB,QADV;AAEE,IAAA,OAAO,EAAEC,SAFX;AAGE,IAAA,QAAQ,EAAEC,UAHZ;AAIE,IAAA,OAAO,EAAEM;AAJX,KAMGT,MANH,CADF,CADD,GAYCK,MApDJ,CADF,CADF,CAFF,CADF;AAgED,CA3GW,CAAd;AA8GAR,KAAK,CAACgC,WAAN,GAAoB,OAApB;eAEehC,K","sourcesContent":["import React, { forwardRef, useMemo, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport styled from '@emotion/styled';\nimport {\n useBodyScroll,\n useKeyPress,\n useClosable,\n omitEmotionProps,\n} from '@os-design/utils';\nimport {\n ellipsisStyles,\n enableScrollingStyles,\n sizeStyles,\n WithSize,\n} from '@os-design/styles';\nimport { m } from '@os-design/media';\nimport { css, keyframes } from '@emotion/react';\nimport { Close } from '@os-design/icons';\nimport { clr, ThemeOverrider, useTheme } from '@os-design/theming';\nimport Portal from '@os-design/portal';\nimport Button from '../Button';\nimport defaultLocale, { ModalLocale } from './utils/defaultLocale';\n\ntype JsxDivProps = Omit<JSX.IntrinsicElements['div'], 'ref'>;\nexport interface ModalProps extends JsxDivProps, WithSize {\n /**\n * The title of the modal.\n * @default undefined\n */\n title?: string;\n /**\n * The text of the OK button.\n * @default OK\n */\n okText?: string;\n /**\n * Sets the danger styles to the OK button.\n * @default false\n */\n okDanger?: boolean;\n /**\n * Whether the OK button is loading.\n * @default false\n */\n okLoading?: boolean;\n /**\n * Whether the OK button is disabled.\n * @default false\n */\n okDisabled?: boolean;\n /**\n * The header component.\n * Set as null if you don't need the default header.\n * @default undefined\n */\n header?: React.ReactNode;\n /**\n * The footer component.\n * Set as null if you don't need the default footer.\n * @default undefined\n */\n footer?: React.ReactNode;\n /**\n * Whether the modal is visible.\n * @default false\n */\n visible?: boolean;\n /**\n * The locale of the modal.\n * @default undefined\n */\n locale?: ModalLocale;\n /**\n * Specifies a callback that will be called when a user clicks the mask or\n * the close button. The callback should set the visible state to false.\n * @default undefined\n */\n onClose?: () => void;\n /**\n * Specifies a callback that will be called when a user clicks the OK button.\n * @default undefined\n */\n onOk?: () => void;\n}\n\nconst MODAL_CONTAINER_Z_INDEX = 1000;\nconst MODAL_BOX_SHADOW_SIZE_EM = 1;\n\nconst maskFadeIn = keyframes`\n from { opacity: 0; }\n to { opacity: 1; }\n`;\n\nconst maskFadeOut = keyframes`\n from { opacity: 1; }\n to { opacity: 0; }\n`;\n\nconst maskVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${maskFadeIn} ${p.theme.transitionDelay}ms forwards;\n `;\n\nconst maskInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${maskFadeOut} ${p.theme.transitionDelay}ms forwards;\n `;\n\ntype MaskProps = Pick<ModalProps, 'visible'>;\nexport const ModalMask = styled('div', omitEmotionProps('visible'))<MaskProps>`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n background-color: ${(p) => clr(p.theme.modalMaskColorBg)};\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n ${maskVisibleStyles};\n ${maskInvisibleStyles};\n`;\n\nconst Container = styled.div`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n\n ${m.min.xs} {\n ${enableScrollingStyles('y')};\n }\n`;\n\nconst contentFadeIn = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n`;\n\nconst contentFadeOut = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentFadeInXs = keyframes`\n from { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(6em); }\n`;\n\nconst contentFadeOutXs = keyframes`\n from { transform: translateY(6em); }\n to { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${contentFadeIn} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeInXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\nconst contentInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${contentFadeOut} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeOutXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\ntype ContentProps = Pick<ModalProps, 'visible' | 'size'>;\nconst Content = styled(\n 'div',\n omitEmotionProps('visible', 'size')\n)<ContentProps>`\n position: absolute;\n display: flex;\n flex-direction: column;\n padding-bottom: env(safe-area-inset-bottom);\n\n background-color: ${(p) => clr(p.theme.colorBg)};\n color: ${(p) => clr(p.theme.colorText)};\n box-shadow: 0 0 ${MODAL_BOX_SHADOW_SIZE_EM}em\n ${(p) => clr(p.theme.modalColorBoxShadow)};\n\n width: 100%;\n max-height: 100%;\n border-radius: ${(p) => p.theme.borderRadius}em\n ${(p) => p.theme.borderRadius}em 0 0;\n\n ${m.min.xs} {\n width: ${(p) => p.theme.modalWidth}em;\n max-height: unset;\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n left: 50%;\n margin-left: ${(p) => -p.theme.modalWidth / 2}em;\n }\n\n ${contentVisibleStyles};\n ${contentInvisibleStyles}\n ${sizeStyles};\n`;\n\nconst Header = styled.div`\n flex-shrink: 0;\n height: ${(p) => p.theme.modalHeaderHeight}em;\n border-bottom: 1px solid ${(p) => clr(p.theme.modalHeaderColorBorderBottom)};\n box-sizing: border-box;\n\n display: flex;\n align-items: center;\n\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n\n ${m.min.xs} {\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n }\n`;\n\nconst Title = styled.div`\n flex: 1;\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n ${ellipsisStyles};\n`;\n\nconst Body = styled.div`\n flex-grow: 1;\n\n padding: ${(p) => p.theme.modalBodyPaddingVertical[0]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n\n ${m.min.xs} {\n padding: ${(p) => p.theme.modalBodyPaddingVertical[1]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n }\n\n ${enableScrollingStyles('y')};\n`;\n\nconst Footer = styled.div`\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em\n ${(p) => p.theme.modalBodyPaddingVertical[0]}em;\n\n ${m.min.xs} {\n display: flex;\n justify-content: flex-end;\n align-items: center;\n\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em\n ${(p) => p.theme.modalBodyPaddingVertical[1]}em;\n }\n`;\n\n/**\n * The base pop-up window.\n */\nconst Modal = forwardRef<HTMLDivElement, ModalProps>(\n (\n {\n title,\n okText = 'OK',\n okDanger = false,\n okLoading = false,\n okDisabled = false,\n header,\n footer,\n visible = false,\n locale = defaultLocale,\n onClose = () => {},\n onOk,\n size,\n id,\n onClick = () => {},\n children,\n ...rest\n },\n ref\n ) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const { theme } = useTheme();\n const mounted = useClosable(visible, theme.transitionDelay);\n useBodyScroll(!visible);\n useKeyPress(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'Escape',\n onClose\n );\n\n const titleId = useMemo(\n () => `modal-title-${Math.random().toString(36).slice(2, 11)}`,\n []\n );\n const bodyId = useMemo(\n () => id || `modal-body-${Math.random().toString(36).slice(2, 11)}`,\n [id]\n );\n\n if (!mounted) return null;\n\n return (\n <Portal>\n <ModalMask visible={visible} />\n <Container onClick={onClose}>\n <FocusLock autoFocus={false}>\n <Content\n visible={visible}\n size={size}\n onClick={(e) => {\n e.stopPropagation();\n onClick(e);\n }}\n role='dialog'\n aria-modal\n aria-labelledby={header === undefined ? titleId : undefined}\n aria-describedby={bodyId}\n ref={contentRef}\n >\n {header === undefined ? (\n <ThemeOverrider\n overrides={(t) => ({\n buttonPaddingHorizontal:\n t.modalCloseButtonPaddingHorizontal,\n })}\n >\n <Header>\n <Title id={titleId}>{title}</Title>\n <Button\n type='ghost'\n wide='never'\n onClick={onClose}\n aria-label={locale.closeLabel}\n >\n <Close />\n </Button>\n </Header>\n </ThemeOverrider>\n ) : (\n header\n )}\n\n <Body id={bodyId} {...rest} ref={ref}>\n {children}\n </Body>\n\n {footer === undefined ? (\n <Footer>\n <Button\n danger={okDanger}\n loading={okLoading}\n disabled={okDisabled}\n onClick={onOk}\n >\n {okText}\n </Button>\n </Footer>\n ) : (\n footer\n )}\n </Content>\n </FocusLock>\n </Container>\n </Portal>\n );\n }\n);\n\nModal.displayName = 'Modal';\n\nexport default Modal;\n"],"file":"index.js"}
|
|
@@ -19,12 +19,14 @@ var _media = require("@os-design/media");
|
|
|
19
19
|
|
|
20
20
|
var _theming = require("@os-design/theming");
|
|
21
21
|
|
|
22
|
+
var _react2 = require("@emotion/react");
|
|
23
|
+
|
|
22
24
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
23
25
|
|
|
24
|
-
var _excluded = ["options", "disabled", "value", "defaultValue", "onChange", "size"],
|
|
26
|
+
var _excluded = ["options", "wide", "disabled", "value", "defaultValue", "onChange", "size"],
|
|
25
27
|
_excluded2 = ["title", "value", "disabled", "onClick"];
|
|
26
28
|
|
|
27
|
-
var _templateObject, _templateObject2;
|
|
29
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
28
30
|
|
|
29
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
30
32
|
|
|
@@ -52,12 +54,20 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
52
54
|
|
|
53
55
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
54
56
|
|
|
55
|
-
var
|
|
57
|
+
var wideDefaultStyles = function wideDefaultStyles(p) {
|
|
58
|
+
return p.wide === 'default' && (0, _react2.css)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", " {\n width: 100%;\n & > button {\n flex: 1;\n }\n }\n "])), _media.m.max.xxs);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
var wideAlwaysStyles = function wideAlwaysStyles(p) {
|
|
62
|
+
return p.wide === 'always' && (0, _react2.css)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 100%;\n & > button {\n flex: 1;\n }\n "])));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var Container = (0, _styled["default"])('div', (0, _utils.omitEmotionProps)('wide', 'disabled', 'size'))(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: inline-flex;\n flex-wrap: wrap;\n\n border-radius: ", "em;\n overflow: hidden;\n border: 1px solid\n ", ";\n\n ", ";\n ", ";\n ", ";\n"])), function (p) {
|
|
56
66
|
return p.theme.borderRadius;
|
|
57
67
|
}, function (p) {
|
|
58
68
|
return p.disabled ? (0, _theming.clr)(p.theme.buttonDisabledGhostColorText) : (0, _theming.clr)(p.theme.colorPrimary);
|
|
59
|
-
},
|
|
60
|
-
var StyledButton = (0, _styled["default"])(_Button["default"])(
|
|
69
|
+
}, wideDefaultStyles, wideAlwaysStyles, _styles.sizeStyles);
|
|
70
|
+
var StyledButton = (0, _styled["default"])(_Button["default"])(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n border-radius: 0;\n"])));
|
|
61
71
|
/**
|
|
62
72
|
* The radio buttons that allow a user to select only one of a limited number of options.
|
|
63
73
|
*/
|
|
@@ -65,6 +75,8 @@ var StyledButton = (0, _styled["default"])(_Button["default"])(_templateObject2
|
|
|
65
75
|
var RadioGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
66
76
|
var _ref$options = _ref.options,
|
|
67
77
|
options = _ref$options === void 0 ? [] : _ref$options,
|
|
78
|
+
_ref$wide = _ref.wide,
|
|
79
|
+
wide = _ref$wide === void 0 ? 'default' : _ref$wide,
|
|
68
80
|
_ref$disabled = _ref.disabled,
|
|
69
81
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
70
82
|
value = _ref.value,
|
|
@@ -84,6 +96,7 @@ var RadioGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
84
96
|
setForwardedValue = _useForwardedState2[1];
|
|
85
97
|
|
|
86
98
|
return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(Container, _extends({
|
|
99
|
+
wide: wide,
|
|
87
100
|
disabled: disabled,
|
|
88
101
|
size: size
|
|
89
102
|
}, rest, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/RadioGroup/index.tsx"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../src/RadioGroup/index.tsx"],"names":["wideDefaultStyles","p","wide","css","m","max","xxs","wideAlwaysStyles","Container","theme","borderRadius","disabled","buttonDisabledGhostColorText","colorPrimary","sizeStyles","StyledButton","Button","RadioGroup","ref","options","value","defaultValue","onChange","size","rest","forwardedValue","setForwardedValue","map","title","valueOption","disabledOption","onClick","buttonRest","e","displayName"],"mappings":";;;;;;;;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HEC,IAGF;;AACH,2BAA4C,8BAAkB;AAC5DJ,IAAAA,KAAK,EAALA,KAD4D;AAE5DC,IAAAA,YAAY,EAAZA,YAF4D;AAG5DC,IAAAA,QAAQ,EAARA;AAH4D,GAAlB,CAA5C;AAAA;AAAA,MAAOG,cAAP;AAAA,MAAuBC,iBAAvB;;AAMA,sBACE,0DACE,gCAAC,SAAD;AACE,IAAA,IAAI,EAAExB,IADR;AAEE,IAAA,QAAQ,EAAES,QAFZ;AAGE,IAAA,IAAI,EAAEY;AAHR,KAIMC,IAJN;AAKE,IAAA,GAAG,EAAEN;AALP,MAOGC,OAPH,aAOGA,OAPH,uBAOGA,OAAO,CAAEQ,GAAT,CACC;AAAA,QACEC,KADF,SACEA,KADF;AAAA,QAESC,WAFT,SAEET,KAFF;AAAA,QAGYU,cAHZ,SAGEnB,QAHF;AAAA,8BAIEoB,OAJF;AAAA,QAIEA,QAJF,8BAIY,YAAM,CAAE,CAJpB;AAAA,QAKKC,UALL;;AAAA,wBAOE,gCAAC,YAAD;AACE,MAAA,GAAG,EAAEH,WADP;AAEE,MAAA,IAAI,EAAEJ,cAAc,KAAKI,WAAnB,GAAiC,SAAjC,GAA6C,OAFrD;AAGE,MAAA,IAAI,EAAC,OAHP;AAIE,MAAA,QAAQ,EAAElB,QAAQ,IAAImB,cAJxB;AAKE,MAAA,OAAO,EAAE,iBAACG,CAAD,EAAO;AACdP,QAAAA,iBAAiB,CAACG,WAAD,CAAjB;;AACAE,QAAAA,QAAO,CAACE,CAAD,CAAP;AACD;AARH,OASMD,UATN,GAWGJ,KAXH,CAPF;AAAA,GADD,CAPH,CADF,CADF;AAmCD,CAvDgB,CAAnB;AA0DAX,UAAU,CAACiB,WAAX,GAAyB,YAAzB;eAEejB,U","sourcesContent":["import React, { forwardRef } from 'react';\nimport { sizeStyles, WithSize } from '@os-design/styles';\nimport { omitEmotionProps, useForwardedState } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { m } from '@os-design/media';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport Button, { ButtonProps } from '../Button';\n\nexport interface RadioGroupOption\n extends Omit<ButtonProps, 'type' | 'wide' | 'size'> {\n /**\n * The title of the option.\n */\n title: string;\n /**\n * The value of the option.\n */\n value: string;\n}\n\ntype JsxDivProps = Omit<\n JSX.IntrinsicElements['div'],\n 'value' | 'defaultValue' | 'onChange' | 'ref'\n>;\nexport interface RadioGroupProps extends JsxDivProps, WithSize {\n /**\n * Options of the radio group.\n * @default undefined\n */\n options?: RadioGroupOption[];\n /**\n * Whether the radio group has full width.\n * Possible values:\n * `default` – the radio group has full width if the screen width is less than xs;\n * `always` – the radio group always has full width;\n * `never` – the radio group never has full width.\n * @default default\n */\n wide?: 'default' | 'always' | 'never';\n /**\n * Whether the radio group is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Selected option.\n * @default false\n */\n value?: string;\n /**\n * The default value.\n * @default undefined\n */\n defaultValue?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string) => void;\n}\n\nconst wideDefaultStyles = (p) =>\n p.wide === 'default' &&\n css`\n ${m.max.xxs} {\n width: 100%;\n & > button {\n flex: 1;\n }\n }\n `;\n\nconst wideAlwaysStyles = (p) =>\n p.wide === 'always' &&\n css`\n width: 100%;\n & > button {\n flex: 1;\n }\n `;\n\ntype ContainerProps = Required<Pick<RadioGroupProps, 'wide' | 'disabled'>> &\n WithSize;\nconst Container = styled(\n 'div',\n omitEmotionProps('wide', 'disabled', 'size')\n)<ContainerProps>`\n display: inline-flex;\n flex-wrap: wrap;\n\n border-radius: ${(p) => p.theme.borderRadius}em;\n overflow: hidden;\n border: 1px solid\n ${(p) =>\n p.disabled\n ? clr(p.theme.buttonDisabledGhostColorText)\n : clr(p.theme.colorPrimary)};\n\n ${wideDefaultStyles};\n ${wideAlwaysStyles};\n ${sizeStyles};\n`;\n\nconst StyledButton = styled(Button)`\n border-radius: 0;\n`;\n\n/**\n * The radio buttons that allow a user to select only one of a limited number of options.\n */\nconst RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(\n (\n {\n options = [],\n wide = 'default',\n disabled = false,\n value,\n defaultValue,\n onChange = () => {},\n size,\n ...rest\n },\n ref\n ) => {\n const [forwardedValue, setForwardedValue] = useForwardedState({\n value,\n defaultValue,\n onChange,\n });\n\n return (\n <div>\n <Container\n wide={wide}\n disabled={disabled}\n size={size}\n {...rest}\n ref={ref}\n >\n {options?.map(\n ({\n title,\n value: valueOption,\n disabled: disabledOption,\n onClick = () => {},\n ...buttonRest\n }) => (\n <StyledButton\n key={valueOption}\n type={forwardedValue === valueOption ? 'primary' : 'ghost'}\n wide='never'\n disabled={disabled || disabledOption}\n onClick={(e) => {\n setForwardedValue(valueOption);\n onClick(e);\n }}\n {...buttonRest}\n >\n {title}\n </StyledButton>\n )\n )}\n </Container>\n </div>\n );\n }\n);\n\nRadioGroup.displayName = 'RadioGroup';\n\nexport default RadioGroup;\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Button/index.tsx"],"names":["React","forwardRef","styled","resetButtonStyles","sizeStyles","transitionStyles","omitEmotionProps","clr","css","m","useButtonColors","ButtonContent","hoverStyles","p","disabled","colors","bgHover","primaryStyles","btnType","text","bg","ghostStyles","outlineStyles","wideDefaultStyles","wide","max","xxs","wideAlwaysStyles","disabledStyles","StyledButton","theme","borderRadius","buttonHeight","buttonPaddingHorizontal","Button","type","danger","left","right","loading","size","children","onMouseDown","rest","ref","buttonColors","loadingColors","e","preventDefault","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,QAAkC,OAAlC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SACEC,iBADF,EAEEC,UAFF,EAGEC,gBAHF,QAKO,mBALP;AAMA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,GAAT,QAAoB,oBAApB;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,SAASC,CAAT,QAA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D,GAAD,CAAvD;AAMA,sBACE,oBAAC,YAAD;AACE,IAAA,OAAO,EAAEqB,IADX;AAEE,IAAA,MAAM,EAAEU,YAFV;AAGE,IAAA,IAAI,EAAErB,IAHR;AAIE,IAAA,OAAO,EAAEe,OAJX;AAKE,IAAA,QAAQ,EAAEzB,QAAQ,IAAIyB,OALxB;AAME,IAAA,IAAI,EAAEC,IANR;AAOE,IAAA,WAAW,EAAGO,CAAD,IAAO;AAClBL,MAAAA,WAAW,CAACK,CAAD,CAAX;AACAA,MAAAA,CAAC,CAACC,cAAF;AACD,KAVH;AAWE,iBAAWT;AAXb,KAYMI,IAZN;AAaE,IAAA,GAAG,EAAEC;AAbP,mBAeE,oBAAC,aAAD;AACE,IAAA,IAAI,EAAEP,IADR;AAEE,IAAA,KAAK,EAAEC,KAFT;AAGE,IAAA,OAAO,EAAEC,OAHX;AAIE,IAAA,aAAa,EAAEO;AAJjB,KAMGL,QANH,CAfF,CADF;AA0BD,CAjDsB,CAAzB;AAoDAP,MAAM,CAACe,WAAP,GAAqB,QAArB;AAEA,eAAef,MAAf","sourcesContent":["import React, { forwardRef } from 'react';\nimport styled from '@emotion/styled';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps } from '@os-design/utils';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { m } from '@os-design/media';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\nimport ButtonContent from './ButtonContent';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button, LinkButton\nexport interface BaseButtonProps extends WithSize {\n /**\n * Type of button styles.\n * @default primary\n */\n type?: 'primary' | 'outline' | 'ghost';\n /**\n * Sets the danger styles.\n * @default false\n */\n danger?: boolean;\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Whether the button has full width.\n * Possible values:\n * `default` – the button has full width if the screen width is less than xs;\n * `always` – the button always has full width;\n * `never` – the button never has full width
|
|
1
|
+
{"version":3,"sources":["../../../src/Button/index.tsx"],"names":["React","forwardRef","styled","resetButtonStyles","sizeStyles","transitionStyles","omitEmotionProps","clr","css","m","useButtonColors","ButtonContent","hoverStyles","p","disabled","colors","bgHover","primaryStyles","btnType","text","bg","ghostStyles","outlineStyles","wideDefaultStyles","wide","max","xxs","wideAlwaysStyles","disabledStyles","StyledButton","theme","borderRadius","buttonHeight","buttonPaddingHorizontal","Button","type","danger","left","right","loading","size","children","onMouseDown","rest","ref","buttonColors","loadingColors","e","preventDefault","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,QAAkC,OAAlC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SACEC,iBADF,EAEEC,UAFF,EAGEC,gBAHF,QAKO,mBALP;AAMA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,GAAT,QAAoB,oBAApB;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,SAASC,CAAT,QAAkB,kBAAlB;AACA,OAAOC,eAAP,MAA8C,yBAA9C;AACA,OAAOC,aAAP,MAA0B,iBAA1B;;AA0DA,MAAMC,WAAW,GAAIC,CAAD,IAClB,CAACA,CAAC,CAACC,QAAH,IACAN,GAAI;AACN;AACA;AACA;AACA,4BAA4BD,GAAG,CAACM,CAAC,CAACE,MAAF,CAASC,OAAV,CAAmB;AAClD;AACA;AACA,GATA;;AAWA,MAAMC,aAAa,GAAIJ,CAAD,IACpBA,CAAC,CAACK,OAAF,KAAc,SAAd,IACAV,GAAI;AACN,aAAaD,GAAG,CAACM,CAAC,CAACE,MAAF,CAASI,IAAV,CAAgB;AAChC,wBAAwBZ,GAAG,CAACM,CAAC,CAACE,MAAF,CAASK,EAAV,CAAc;AACzC,MAAMR,WAAW,CAACC,CAAD,CAAI;AACrB,GANA;;AAQA,MAA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EAAEC,OAHX;AAIE,IAAA,aAAa,EAAEO;AAJjB,KAMGL,QANH,CAfF,CADF;AA0BD,CAjDsB,CAAzB;AAoDAP,MAAM,CAACe,WAAP,GAAqB,QAArB;AAEA,eAAef,MAAf","sourcesContent":["import React, { forwardRef } from 'react';\nimport styled from '@emotion/styled';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps } from '@os-design/utils';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { m } from '@os-design/media';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\nimport ButtonContent from './ButtonContent';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button, LinkButton\nexport interface BaseButtonProps extends WithSize {\n /**\n * Type of button styles.\n * @default primary\n */\n type?: 'primary' | 'outline' | 'ghost';\n /**\n * Sets the danger styles.\n * @default false\n */\n danger?: boolean;\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Whether the button has full width.\n * Possible values:\n * `default` – the button has full width if the screen width is less than xs;\n * `always` – the button always has full width;\n * `never` – the button never has full width.\n * @default default\n */\n wide?: 'default' | 'always' | 'never';\n /**\n * Shows the loading status and disables the button.\n * @default false\n */\n loading?: boolean;\n /**\n * Whether the button is disabled.\n * @default false\n */\n disabled?: boolean;\n}\n\nexport type ButtonProps = JsxButtonProps & BaseButtonProps;\n\ninterface StyledButtonProps\n extends Pick<ButtonProps, 'wide' | 'loading' | 'disabled' | 'size'> {\n btnType: ButtonProps['type'];\n colors: ButtonColors;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover,\n &:focus {\n background-color: ${clr(p.colors.bgHover)};\n }\n }\n `;\n\nconst primaryStyles = (p) =>\n p.btnType === 'primary' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: ${clr(p.colors.bg)};\n ${hoverStyles(p)};\n `;\n\nconst ghostStyles = (p) =>\n p.btnType === 'ghost' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: transparent;\n ${hoverStyles(p)};\n `;\n\nconst outlineStyles = (p) =>\n p.btnType === 'outline' &&\n css`\n color: ${clr(p.colors.text)};\n background-color: transparent;\n border: 1px solid currentColor;\n ${hoverStyles(p)};\n `;\n\nconst wideDefaultStyles = (p) =>\n p.wide === 'default' &&\n css`\n ${m.max.xxs} {\n width: 100%;\n }\n `;\n\nconst wideAlwaysStyles = (p) =>\n p.wide === 'always' &&\n css`\n width: 100%;\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n `;\n\nexport const StyledButton = styled(\n 'button',\n omitEmotionProps('btnType', 'colors', 'wide', 'loading', 'size')\n)<StyledButtonProps>`\n ${resetButtonStyles};\n position: relative; // Because LoadingContainer has an absolute position\n cursor: pointer;\n user-select: none;\n box-sizing: border-box; // Important for LinkButton\n\n // Disable multiline\n white-space: nowrap;\n overflow: hidden;\n\n border-radius: ${(p) => p.theme.borderRadius}em;\n height: ${(p) => p.theme.buttonHeight}em;\n padding: 0 ${(p) => p.theme.buttonPaddingHorizontal}em;\n\n // Do not set inline-flex, otherwise the mobile safari cuts off\n // the bottom border of the button (tested in iPhone 6)\n display: flex;\n justify-content: center;\n align-items: center;\n\n font-weight: 500;\n line-height: 1;\n\n ${primaryStyles};\n ${outlineStyles};\n ${ghostStyles};\n\n ${wideDefaultStyles};\n ${wideAlwaysStyles};\n\n ${disabledStyles};\n\n ${sizeStyles};\n ${transitionStyles('background-color', 'color')};\n`;\n\n/**\n * Used to trigger the corresponding business logic.\n */\nconst Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n type = 'primary',\n danger = false,\n left,\n right,\n wide = 'default',\n loading = false,\n disabled = false,\n size,\n children,\n onMouseDown = () => {},\n ...rest\n },\n ref\n ) => {\n const { buttonColors, loadingColors } = useButtonColors({\n type,\n danger,\n disabled,\n });\n\n return (\n <StyledButton\n btnType={type}\n colors={buttonColors}\n wide={wide}\n loading={loading}\n disabled={disabled || loading}\n size={size}\n onMouseDown={(e) => {\n onMouseDown(e);\n e.preventDefault();\n }}\n aria-busy={loading}\n {...rest}\n ref={ref}\n >\n <ButtonContent\n left={left}\n right={right}\n loading={loading}\n loadingColors={loadingColors}\n >\n {children}\n </ButtonContent>\n </StyledButton>\n );\n }\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"file":"index.js"}
|
package/dist/esm/Input/index.js
CHANGED
|
@@ -122,6 +122,7 @@ const Input = /*#__PURE__*/forwardRef(({
|
|
|
122
122
|
containerRef,
|
|
123
123
|
containerProps = {},
|
|
124
124
|
size,
|
|
125
|
+
value,
|
|
125
126
|
onChange = () => {},
|
|
126
127
|
...rest
|
|
127
128
|
}, ref) => {
|
|
@@ -165,6 +166,7 @@ const Input = /*#__PURE__*/forwardRef(({
|
|
|
165
166
|
disabled: disabled,
|
|
166
167
|
hasLeft: !!left,
|
|
167
168
|
hasRight: !!right,
|
|
169
|
+
value: value || '',
|
|
168
170
|
onChange: e => onChange(e.target.value, e)
|
|
169
171
|
}, rest, {
|
|
170
172
|
ref: ref
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Input/index.tsx"],"names":["React","forwardRef","useMemo","resetFocusStyles","sizeStyles","transitionStyles","omitEmotionProps","useForwardedRef","styled","clr","ThemeOverrider","css","Loading","getFocusableElements","hoverStyles","p","disabled","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","onChange","rest","ref","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","value","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAA2CC,UAA3C,EAAuDC,OAAvD,QAAsE,OAAtE;AACA,SACEC,gBADF,EAEEC,UAFF,EAGEC,gBAHF,QAKO,mBALP;AAMA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,kBAAlD;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,GAAT,EAAcC,cAAd,QAAoC,oBAApC;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,SAASC,OAAT,QAAwB,kBAAxB;AACA,OAAOC,oBAAP,MAAiC,8BAAjC;;AAkEA,MAAMC,WAAW,GAAIC,CAAD,IAClB,CAACA,CAAC,CAACC,QAAH,IACAL,GAAI;AACN;AACA;AACA,wBAAwBF,GAAG,CAACM,CAAC,CAACE,KAAF,CAAQC,qBAAT,CAAgC;AAC3D;AACA;AACA,GARA;;AAUA,MAAMC,WAAW,GAAIJ,CAAD,IAClB,CAACA,CAAC,CAACC,QAAH,IACAL,GAAI;AACN;AACA,sBAAsBF,GAAG,CAACM,CAAC,CAACE,KAAF,CAAQG,qBAAT,CAAgC;AACzD,iCAAiCX,GAAG,CAACM,CAAC,CAACE,KAAF,CAAQI,qBAAT,CAAgC;AACpE;AACA,GAPA;;AASA,MAAMC,cAAc,GAAIP,CAAD,IACrBA,CAAC,CAACC,QAAF,IACAL,GAAI;AACN;AACA,aAAaF,GAAG,CAACM,CAAC,CAACE,KAAF,CAAQM,sBAAT,CAAiC;AACjD,wBAAwBd,GAAG,CAACM,CAAC,CAACE,KAAF,CAAQO,oBAAT,CAA+B;AAC1D,oB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AAelC,KAAf","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/Input/index.tsx"],"names":["React","forwardRef","useMemo","resetFocusStyles","sizeStyles","transitionStyles","omitEmotionProps","useForwardedRef","styled","clr","ThemeOverrider","css","Loading","getFocusableElements","hoverStyles","p","disabled","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","value","onChange","rest","ref","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAA2CC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B,KAAK,CAA5B,EAA+B;AAC/B,cAAMG,2BAA2B,GAC/BX,iBAAiB,CAACQ,mBAAmB,GAAG,CAAvB,CADnB;AAEAG,QAAAA,2BAA2B,CAACV,KAA5B;AACD;AACF,KA/BH;AAgCE,IAAA,GAAG,EAAEP;AAhCP,KAiCMP,cAjCN,GAmCGN,IAAI,iBACH,oBAAC,cAAD;AAAgB,IAAA,SAAS,EAAE;AAAE+B,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,oBAAC,SAAD;AAAW,IAAA,UAAU,EAAE9B;AAAvB,KAAwCD,IAAxC,CADF,CApCJ,eAyCE,oBAAC,WAAD;AACE,IAAA,IAAI,EAAED,IADR;AAEE,IAAA,QAAQ,EAAE/B,QAFZ;AAGE,IAAA,OAAO,EAAE,CAAC,CAACgC,IAHb;AAIE,IAAA,QAAQ,EAAE,CAAC,CAACE,KAJd;AAKE,IAAA,KAAK,EAAEM,KAAK,IAAI,EALlB;AAME,IAAA,QAAQ,EAAGQ,CAAD,IAAOP,QAAQ,CAACO,CAAC,CAACC,MAAF,CAAST,KAAV,EAAiBQ,CAAjB;AAN3B,KAOMN,IAPN;AAQE,IAAA,GAAG,EAAEC;AARP,KAzCF,EAoDGG,UAAU,iBACT,oBAAC,cAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,oBAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CArDJ,CADF;AA8DD,CA9FqB,CAAxB;AAiGAhB,KAAK,CAACkC,WAAN,GAAoB,OAApB;AAEA,eAAelC,KAAf","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n value,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n value={value || ''}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
|
package/dist/esm/Modal/index.js
CHANGED
|
@@ -3,7 +3,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
3
3
|
import React, { forwardRef, useMemo, useRef } from 'react';
|
|
4
4
|
import FocusLock from 'react-focus-lock';
|
|
5
5
|
import styled from '@emotion/styled';
|
|
6
|
-
import { useBodyScroll,
|
|
6
|
+
import { useBodyScroll, useKeyPress, useClosable, omitEmotionProps } from '@os-design/utils';
|
|
7
7
|
import { ellipsisStyles, enableScrollingStyles, sizeStyles } from '@os-design/styles';
|
|
8
8
|
import { m } from '@os-design/media';
|
|
9
9
|
import { css, keyframes } from '@emotion/react';
|
|
@@ -181,6 +181,7 @@ const Modal = /*#__PURE__*/forwardRef(({
|
|
|
181
181
|
onOk,
|
|
182
182
|
size,
|
|
183
183
|
id,
|
|
184
|
+
onClick = () => {},
|
|
184
185
|
children,
|
|
185
186
|
...rest
|
|
186
187
|
}, ref) => {
|
|
@@ -190,18 +191,23 @@ const Modal = /*#__PURE__*/forwardRef(({
|
|
|
190
191
|
} = useTheme();
|
|
191
192
|
const mounted = useClosable(visible, theme.transitionDelay);
|
|
192
193
|
useBodyScroll(!visible);
|
|
193
|
-
useClickOutside(contentRef, onClose);
|
|
194
194
|
useKeyPress(typeof window !== 'undefined' ? window : undefined, 'Escape', onClose);
|
|
195
195
|
const titleId = useMemo(() => `modal-title-${Math.random().toString(36).slice(2, 11)}`, []);
|
|
196
196
|
const bodyId = useMemo(() => id || `modal-body-${Math.random().toString(36).slice(2, 11)}`, [id]);
|
|
197
197
|
if (!mounted) return null;
|
|
198
198
|
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(ModalMask, {
|
|
199
199
|
visible: visible
|
|
200
|
-
}), /*#__PURE__*/React.createElement(Container,
|
|
200
|
+
}), /*#__PURE__*/React.createElement(Container, {
|
|
201
|
+
onClick: onClose
|
|
202
|
+
}, /*#__PURE__*/React.createElement(FocusLock, {
|
|
201
203
|
autoFocus: false
|
|
202
204
|
}, /*#__PURE__*/React.createElement(Content, {
|
|
203
205
|
visible: visible,
|
|
204
206
|
size: size,
|
|
207
|
+
onClick: e => {
|
|
208
|
+
e.stopPropagation();
|
|
209
|
+
onClick(e);
|
|
210
|
+
},
|
|
205
211
|
role: "dialog",
|
|
206
212
|
"aria-modal": true,
|
|
207
213
|
"aria-labelledby": header === undefined ? titleId : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Modal/index.tsx"],"names":["React","forwardRef","useMemo","useRef","FocusLock","styled","useBodyScroll","useClickOutside","useKeyPress","useClosable","omitEmotionProps","ellipsisStyles","enableScrollingStyles","sizeStyles","m","css","keyframes","Close","clr","ThemeOverrider","useTheme","Portal","Button","defaultLocale","MODAL_CONTAINER_Z_INDEX","MODAL_BOX_SHADOW_SIZE_EM","maskFadeIn","maskFadeOut","maskVisibleStyles","p","visible","theme","transitionDelay","maskInvisibleStyles","ModalMask","modalMaskColorBg","Container","div","min","xs","contentFadeIn","contentFadeOut","contentFadeInXs","contentFadeOutXs","contentVisibleStyles","contentInvisibleStyles","Content","colorBg","colorText","modalColorBoxShadow","borderRadius","modalWidth","Header","modalHeaderHeight","modalHeaderColorBorderBottom","modalBodyPaddingHorizontal","Math","max","buttonPaddingHorizontal","Title","sizes","large","Body","modalBodyPaddingVertical","Footer","Modal","title","okText","okDanger","okLoading","okDisabled","header","footer","locale","onClose","onOk","size","id","children","rest","ref","contentRef","mounted","window","undefined","titleId","random","toString","slice","bodyId","t","modalCloseButtonPaddingHorizontal","closeLabel","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,OAA5B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SACEC,aADF,EAEEC,eAFF,EAGEC,WAHF,EAIEC,WAJF,EAKEC,gBALF,QAMO,kBANP;AAOA,SACEC,cADF,EAEEC,qBAFF,EAGEC,UAHF,QAKO,mBALP;AAMA,SAASC,CAAT,QAAkB,kBAAlB;AACA,SAASC,GAAT,EAAcC,SAAd,QAA+B,gBAA/B;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,GAAT,EAAcC,cAAd,EAA8BC,QAA9B,QAA8C,oBAA9C;AACA,OAAOC,MAAP,MAAmB,mBAAnB;AACA,OAAOC,MAAP,MAAmB,WAAnB;AACA,OAAOC,aAAP,MAA2C,uBAA3C;AAgEA,MAAMC,uBAAuB,GAAG,IAAhC;AACA,MAAMC,wBAAwB,GAAG,CAAjC;AAEA,MAAMC,UAAU,GAAGV,SAAU;AAC7B;AACA;AACA,CAHA;AAKA,MAAMW,WAAW,GAAGX,SAAU;AAC9B;AACA;AACA,CAHA;;AAKA,MAAMY,iBAAiB,GAAIC,CAAD,IACxBA,CAAC,CAACC,OAAF,IACAf,GAAI;AACN,iBAAiBW,UAAW,IAAGG,CAAC,CAACE,KAAF,CAAQC,eAAgB;AACvD,GAJA;;AAMA,MAAMC,mBAAmB,GAAIJ,CAAD,IAC1B,CAACA,CAAC,CAACC,OAAH,IACAf,GAAI;AACN,iBAAiBY,WAAY,IAAGE,CAAC,CAACE,KAAF,CAAQC,eAAgB;AACxD,GAJA;;AAOA,OAAO,MAAME,SAAS,GAAG7B,MAAM,CAAC,KAAD,EAAQK,gBAAgB,CAAC,SAAD,CAAxB,CAAgD;AAC/E;AACA;AACA;AACA;AACA;AACA,sBA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AgCE,oBAAC,IAAD;AAAM,IAAA,EAAE,EAAEkB;AAAV,KAAsBV,IAAtB;AAA4B,IAAA,GAAG,EAAEC;AAAjC,MACGF,QADH,CAhCF,EAoCGN,MAAM,KAAKY,SAAX,gBACC,oBAAC,MAAD,qBACE,oBAAC,MAAD;AACE,IAAA,MAAM,EAAEhB,QADV;AAEE,IAAA,OAAO,EAAEC,SAFX;AAGE,IAAA,QAAQ,EAAEC,UAHZ;AAIE,IAAA,OAAO,EAAEK;AAJX,KAMGR,MANH,CADF,CADD,GAYCK,MAhDJ,CADF,CADF,CAFF,CADF;AA4DD,CAvGqB,CAAxB;AA0GAP,KAAK,CAAC4B,WAAN,GAAoB,OAApB;AAEA,eAAe5B,KAAf","sourcesContent":["import React, { forwardRef, useMemo, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport styled from '@emotion/styled';\nimport {\n useBodyScroll,\n useClickOutside,\n useKeyPress,\n useClosable,\n omitEmotionProps,\n} from '@os-design/utils';\nimport {\n ellipsisStyles,\n enableScrollingStyles,\n sizeStyles,\n WithSize,\n} from '@os-design/styles';\nimport { m } from '@os-design/media';\nimport { css, keyframes } from '@emotion/react';\nimport { Close } from '@os-design/icons';\nimport { clr, ThemeOverrider, useTheme } from '@os-design/theming';\nimport Portal from '@os-design/portal';\nimport Button from '../Button';\nimport defaultLocale, { ModalLocale } from './utils/defaultLocale';\n\ntype JsxDivProps = Omit<JSX.IntrinsicElements['div'], 'ref'>;\nexport interface ModalProps extends JsxDivProps, WithSize {\n /**\n * The title of the modal.\n * @default undefined\n */\n title?: string;\n /**\n * The text of the OK button.\n * @default OK\n */\n okText?: string;\n /**\n * Sets the danger styles to the OK button.\n * @default false\n */\n okDanger?: boolean;\n /**\n * Whether the OK button is loading.\n * @default false\n */\n okLoading?: boolean;\n /**\n * Whether the OK button is disabled.\n * @default false\n */\n okDisabled?: boolean;\n /**\n * The header component.\n * Set as null if you don't need the default header.\n * @default undefined\n */\n header?: React.ReactNode;\n /**\n * The footer component.\n * Set as null if you don't need the default footer.\n * @default undefined\n */\n footer?: React.ReactNode;\n /**\n * Whether the modal is visible.\n * @default false\n */\n visible?: boolean;\n /**\n * The locale of the modal.\n * @default undefined\n */\n locale?: ModalLocale;\n /**\n * Specifies a callback that will be called when a user clicks the mask or\n * the close button. The callback should set the visible state to false.\n * @default undefined\n */\n onClose?: () => void;\n /**\n * Specifies a callback that will be called when a user clicks the OK button.\n * @default undefined\n */\n onOk?: () => void;\n}\n\nconst MODAL_CONTAINER_Z_INDEX = 1000;\nconst MODAL_BOX_SHADOW_SIZE_EM = 1;\n\nconst maskFadeIn = keyframes`\n from { opacity: 0; }\n to { opacity: 1; }\n`;\n\nconst maskFadeOut = keyframes`\n from { opacity: 1; }\n to { opacity: 0; }\n`;\n\nconst maskVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${maskFadeIn} ${p.theme.transitionDelay}ms forwards;\n `;\n\nconst maskInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${maskFadeOut} ${p.theme.transitionDelay}ms forwards;\n `;\n\ntype MaskProps = Pick<ModalProps, 'visible'>;\nexport const ModalMask = styled('div', omitEmotionProps('visible'))<MaskProps>`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n background-color: ${(p) => clr(p.theme.modalMaskColorBg)};\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n ${maskVisibleStyles};\n ${maskInvisibleStyles};\n`;\n\nconst Container = styled.div`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n\n ${m.min.xs} {\n ${enableScrollingStyles('y')};\n }\n`;\n\nconst contentFadeIn = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n`;\n\nconst contentFadeOut = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentFadeInXs = keyframes`\n from { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(6em); }\n`;\n\nconst contentFadeOutXs = keyframes`\n from { transform: translateY(6em); }\n to { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${contentFadeIn} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeInXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\nconst contentInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${contentFadeOut} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeOutXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\ntype ContentProps = Pick<ModalProps, 'visible' | 'size'>;\nconst Content = styled(\n 'div',\n omitEmotionProps('visible', 'size')\n)<ContentProps>`\n position: absolute;\n display: flex;\n flex-direction: column;\n padding-bottom: env(safe-area-inset-bottom);\n\n background-color: ${(p) => clr(p.theme.colorBg)};\n color: ${(p) => clr(p.theme.colorText)};\n box-shadow: 0 0 ${MODAL_BOX_SHADOW_SIZE_EM}em\n ${(p) => clr(p.theme.modalColorBoxShadow)};\n\n width: 100%;\n max-height: 100%;\n border-radius: ${(p) => p.theme.borderRadius}em\n ${(p) => p.theme.borderRadius}em 0 0;\n\n ${m.min.xs} {\n width: ${(p) => p.theme.modalWidth}em;\n max-height: unset;\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n left: 50%;\n margin-left: ${(p) => -p.theme.modalWidth / 2}em;\n }\n\n ${contentVisibleStyles};\n ${contentInvisibleStyles}\n ${sizeStyles};\n`;\n\nconst Header = styled.div`\n flex-shrink: 0;\n height: ${(p) => p.theme.modalHeaderHeight}em;\n border-bottom: 1px solid ${(p) => clr(p.theme.modalHeaderColorBorderBottom)};\n box-sizing: border-box;\n\n display: flex;\n align-items: center;\n\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n\n ${m.min.xs} {\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n }\n`;\n\nconst Title = styled.div`\n flex: 1;\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n ${ellipsisStyles};\n`;\n\nconst Body = styled.div`\n flex-grow: 1;\n\n padding: ${(p) => p.theme.modalBodyPaddingVertical[0]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n\n ${m.min.xs} {\n padding: ${(p) => p.theme.modalBodyPaddingVertical[1]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n }\n\n ${enableScrollingStyles('y')};\n`;\n\nconst Footer = styled.div`\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em\n ${(p) => p.theme.modalBodyPaddingVertical[0]}em;\n\n ${m.min.xs} {\n display: flex;\n justify-content: flex-end;\n align-items: center;\n\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em\n ${(p) => p.theme.modalBodyPaddingVertical[1]}em;\n }\n`;\n\n/**\n * The base pop-up window.\n */\nconst Modal = forwardRef<HTMLDivElement, ModalProps>(\n (\n {\n title,\n okText = 'OK',\n okDanger = false,\n okLoading = false,\n okDisabled = false,\n header,\n footer,\n visible = false,\n locale = defaultLocale,\n onClose = () => {},\n onOk,\n size,\n id,\n children,\n ...rest\n },\n ref\n ) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const { theme } = useTheme();\n const mounted = useClosable(visible, theme.transitionDelay);\n useBodyScroll(!visible);\n useClickOutside(contentRef, onClose);\n useKeyPress(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'Escape',\n onClose\n );\n\n const titleId = useMemo(\n () => `modal-title-${Math.random().toString(36).slice(2, 11)}`,\n []\n );\n const bodyId = useMemo(\n () => id || `modal-body-${Math.random().toString(36).slice(2, 11)}`,\n [id]\n );\n\n if (!mounted) return null;\n\n return (\n <Portal>\n <ModalMask visible={visible} />\n <Container>\n <FocusLock autoFocus={false}>\n <Content\n visible={visible}\n size={size}\n role='dialog'\n aria-modal\n aria-labelledby={header === undefined ? titleId : undefined}\n aria-describedby={bodyId}\n ref={contentRef}\n >\n {header === undefined ? (\n <ThemeOverrider\n overrides={(t) => ({\n buttonPaddingHorizontal:\n t.modalCloseButtonPaddingHorizontal,\n })}\n >\n <Header>\n <Title id={titleId}>{title}</Title>\n <Button\n type='ghost'\n wide='never'\n onClick={onClose}\n aria-label={locale.closeLabel}\n >\n <Close />\n </Button>\n </Header>\n </ThemeOverrider>\n ) : (\n header\n )}\n\n <Body id={bodyId} {...rest} ref={ref}>\n {children}\n </Body>\n\n {footer === undefined ? (\n <Footer>\n <Button\n danger={okDanger}\n loading={okLoading}\n disabled={okDisabled}\n onClick={onOk}\n >\n {okText}\n </Button>\n </Footer>\n ) : (\n footer\n )}\n </Content>\n </FocusLock>\n </Container>\n </Portal>\n );\n }\n);\n\nModal.displayName = 'Modal';\n\nexport default Modal;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/Modal/index.tsx"],"names":["React","forwardRef","useMemo","useRef","FocusLock","styled","useBodyScroll","useKeyPress","useClosable","omitEmotionProps","ellipsisStyles","enableScrollingStyles","sizeStyles","m","css","keyframes","Close","clr","ThemeOverrider","useTheme","Portal","Button","defaultLocale","MODAL_CONTAINER_Z_INDEX","MODAL_BOX_SHADOW_SIZE_EM","maskFadeIn","maskFadeOut","maskVisibleStyles","p","visible","theme","transitionDelay","maskInvisibleStyles","ModalMask","modalMaskColorBg","Container","div","min","xs","contentFadeIn","contentFadeOut","contentFadeInXs","contentFadeOutXs","contentVisibleStyles","contentInvisibleStyles","Content","colorBg","colorText","modalColorBoxShadow","borderRadius","modalWidth","Header","modalHeaderHeight","modalHeaderColorBorderBottom","modalBodyPaddingHorizontal","Math","max","buttonPaddingHorizontal","Title","sizes","large","Body","modalBodyPaddingVertical","Footer","Modal","title","okText","okDanger","okLoading","okDisabled","header","footer","locale","onClose","onOk","size","id","onClick","children","rest","ref","contentRef","mounted","window","undefined","titleId","random","toString","slice","bodyId","e","stopPropagation","t","modalCloseButtonPaddingHorizontal","closeLabel","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,OAA5B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SACEC,aADF,EAEEC,WAFF,EAGEC,WAHF,EAIEC,gBAJF,QAKO,kBALP;AAMA,SACEC,cADF,EAEEC,qBAFF,EAGEC,UAHF,QAKO,mBALP;AAMA,SAASC,CAAT,QAAkB,kBAAlB;AACA,SAASC,GAAT,EAAcC,SAAd,QAA+B,gBAA/B;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,GAAT,EAAcC,cAAd,EAA8BC,QAA9B,QAA8C,oBAA9C;AACA,OAAOC,MAAP,MAAmB,mBAAnB;AACA,OAAOC,MAAP,MAAmB,WAAnB;AACA,OAAOC,aAAP,MAA2C,uBAA3C;AAgEA,MAAMC,uBAAuB,GAAG,IAAhC;AACA,MAAMC,wBAAwB,GAAG,CAAjC;AAEA,MAAMC,UAAU,GAAGV,SAAU;AAC7B;AACA;AACA,CAHA;AAKA,MAAMW,WAAW,GAAGX,SAAU;AAC9B;AACA;AACA,CAHA;;AAKA,MAAMY,iBAAiB,GAAIC,CAAD,IACxBA,CAAC,CAACC,OAAF,IACAf,GAAI;AACN,iBAAiBW,UAAW,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wBAAkBK,MAVpB;AAWE,IAAA,GAAG,EAAER;AAXP,KAaGX,MAAM,KAAKc,SAAX,gBACC,oBAAC,cAAD;AACE,IAAA,SAAS,EAAGQ,CAAD,KAAQ;AACjBnC,MAAAA,uBAAuB,EACrBmC,CAAC,CAACC;AAFa,KAAR;AADb,kBAME,oBAAC,MAAD,qBACE,oBAAC,KAAD;AAAO,IAAA,EAAE,EAAER;AAAX,KAAqBpB,KAArB,CADF,eAEE,oBAAC,MAAD;AACE,IAAA,IAAI,EAAC,OADP;AAEE,IAAA,IAAI,EAAC,OAFP;AAGE,IAAA,OAAO,EAAEQ,OAHX;AAIE,kBAAYD,MAAM,CAACsB;AAJrB,kBAME,oBAAC,KAAD,OANF,CAFF,CANF,CADD,GAoBCxB,MAjCJ,eAoCE,oBAAC,IAAD;AAAM,IAAA,EAAE,EAAEmB;AAAV,KAAsBV,IAAtB;AAA4B,IAAA,GAAG,EAAEC;AAAjC,MACGF,QADH,CApCF,EAwCGP,MAAM,KAAKa,SAAX,gBACC,oBAAC,MAAD,qBACE,oBAAC,MAAD;AACE,IAAA,MAAM,EAAEjB,QADV;AAEE,IAAA,OAAO,EAAEC,SAFX;AAGE,IAAA,QAAQ,EAAEC,UAHZ;AAIE,IAAA,OAAO,EAAEK;AAJX,KAMGR,MANH,CADF,CADD,GAYCK,MApDJ,CADF,CADF,CAFF,CADF;AAgED,CA3GqB,CAAxB;AA8GAP,KAAK,CAAC+B,WAAN,GAAoB,OAApB;AAEA,eAAe/B,KAAf","sourcesContent":["import React, { forwardRef, useMemo, useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport styled from '@emotion/styled';\nimport {\n useBodyScroll,\n useKeyPress,\n useClosable,\n omitEmotionProps,\n} from '@os-design/utils';\nimport {\n ellipsisStyles,\n enableScrollingStyles,\n sizeStyles,\n WithSize,\n} from '@os-design/styles';\nimport { m } from '@os-design/media';\nimport { css, keyframes } from '@emotion/react';\nimport { Close } from '@os-design/icons';\nimport { clr, ThemeOverrider, useTheme } from '@os-design/theming';\nimport Portal from '@os-design/portal';\nimport Button from '../Button';\nimport defaultLocale, { ModalLocale } from './utils/defaultLocale';\n\ntype JsxDivProps = Omit<JSX.IntrinsicElements['div'], 'ref'>;\nexport interface ModalProps extends JsxDivProps, WithSize {\n /**\n * The title of the modal.\n * @default undefined\n */\n title?: string;\n /**\n * The text of the OK button.\n * @default OK\n */\n okText?: string;\n /**\n * Sets the danger styles to the OK button.\n * @default false\n */\n okDanger?: boolean;\n /**\n * Whether the OK button is loading.\n * @default false\n */\n okLoading?: boolean;\n /**\n * Whether the OK button is disabled.\n * @default false\n */\n okDisabled?: boolean;\n /**\n * The header component.\n * Set as null if you don't need the default header.\n * @default undefined\n */\n header?: React.ReactNode;\n /**\n * The footer component.\n * Set as null if you don't need the default footer.\n * @default undefined\n */\n footer?: React.ReactNode;\n /**\n * Whether the modal is visible.\n * @default false\n */\n visible?: boolean;\n /**\n * The locale of the modal.\n * @default undefined\n */\n locale?: ModalLocale;\n /**\n * Specifies a callback that will be called when a user clicks the mask or\n * the close button. The callback should set the visible state to false.\n * @default undefined\n */\n onClose?: () => void;\n /**\n * Specifies a callback that will be called when a user clicks the OK button.\n * @default undefined\n */\n onOk?: () => void;\n}\n\nconst MODAL_CONTAINER_Z_INDEX = 1000;\nconst MODAL_BOX_SHADOW_SIZE_EM = 1;\n\nconst maskFadeIn = keyframes`\n from { opacity: 0; }\n to { opacity: 1; }\n`;\n\nconst maskFadeOut = keyframes`\n from { opacity: 1; }\n to { opacity: 0; }\n`;\n\nconst maskVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${maskFadeIn} ${p.theme.transitionDelay}ms forwards;\n `;\n\nconst maskInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${maskFadeOut} ${p.theme.transitionDelay}ms forwards;\n `;\n\ntype MaskProps = Pick<ModalProps, 'visible'>;\nexport const ModalMask = styled('div', omitEmotionProps('visible'))<MaskProps>`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n background-color: ${(p) => clr(p.theme.modalMaskColorBg)};\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n ${maskVisibleStyles};\n ${maskInvisibleStyles};\n`;\n\nconst Container = styled.div`\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n z-index: ${MODAL_CONTAINER_Z_INDEX};\n\n ${m.min.xs} {\n ${enableScrollingStyles('y')};\n }\n`;\n\nconst contentFadeIn = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n`;\n\nconst contentFadeOut = keyframes`\n from { transform: translateY(calc(var(--vh, 1vh) * 100 - 100%)); }\n to { transform: translateY(calc(var(--vh, 1vh) * 100 + ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentFadeInXs = keyframes`\n from { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n to { transform: translateY(6em); }\n`;\n\nconst contentFadeOutXs = keyframes`\n from { transform: translateY(6em); }\n to { transform: translateY(calc(-100% - ${MODAL_BOX_SHADOW_SIZE_EM}em)); }\n`;\n\nconst contentVisibleStyles = (p) =>\n p.visible &&\n css`\n animation: ${contentFadeIn} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeInXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\nconst contentInvisibleStyles = (p) =>\n !p.visible &&\n css`\n animation: ${contentFadeOut} ${p.theme.transitionDelay}ms forwards;\n ${m.min.xs} {\n animation: ${contentFadeOutXs} ${p.theme.transitionDelay}ms forwards;\n }\n `;\n\ntype ContentProps = Pick<ModalProps, 'visible' | 'size'>;\nconst Content = styled(\n 'div',\n omitEmotionProps('visible', 'size')\n)<ContentProps>`\n position: absolute;\n display: flex;\n flex-direction: column;\n padding-bottom: env(safe-area-inset-bottom);\n\n background-color: ${(p) => clr(p.theme.colorBg)};\n color: ${(p) => clr(p.theme.colorText)};\n box-shadow: 0 0 ${MODAL_BOX_SHADOW_SIZE_EM}em\n ${(p) => clr(p.theme.modalColorBoxShadow)};\n\n width: 100%;\n max-height: 100%;\n border-radius: ${(p) => p.theme.borderRadius}em\n ${(p) => p.theme.borderRadius}em 0 0;\n\n ${m.min.xs} {\n width: ${(p) => p.theme.modalWidth}em;\n max-height: unset;\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n left: 50%;\n margin-left: ${(p) => -p.theme.modalWidth / 2}em;\n }\n\n ${contentVisibleStyles};\n ${contentInvisibleStyles}\n ${sizeStyles};\n`;\n\nconst Header = styled.div`\n flex-shrink: 0;\n height: ${(p) => p.theme.modalHeaderHeight}em;\n border-bottom: 1px solid ${(p) => clr(p.theme.modalHeaderColorBorderBottom)};\n box-sizing: border-box;\n\n display: flex;\n align-items: center;\n\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n\n ${m.min.xs} {\n padding-left: ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n padding-right: ${(p) =>\n Math.max(\n p.theme.modalBodyPaddingHorizontal[1] - p.theme.buttonPaddingHorizontal,\n 0\n )}em;\n }\n`;\n\nconst Title = styled.div`\n flex: 1;\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n ${ellipsisStyles};\n`;\n\nconst Body = styled.div`\n flex-grow: 1;\n\n padding: ${(p) => p.theme.modalBodyPaddingVertical[0]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em;\n\n ${m.min.xs} {\n padding: ${(p) => p.theme.modalBodyPaddingVertical[1]}em\n ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em;\n }\n\n ${enableScrollingStyles('y')};\n`;\n\nconst Footer = styled.div`\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[0]}em\n ${(p) => p.theme.modalBodyPaddingVertical[0]}em;\n\n ${m.min.xs} {\n display: flex;\n justify-content: flex-end;\n align-items: center;\n\n padding: 0 ${(p) => p.theme.modalBodyPaddingHorizontal[1]}em\n ${(p) => p.theme.modalBodyPaddingVertical[1]}em;\n }\n`;\n\n/**\n * The base pop-up window.\n */\nconst Modal = forwardRef<HTMLDivElement, ModalProps>(\n (\n {\n title,\n okText = 'OK',\n okDanger = false,\n okLoading = false,\n okDisabled = false,\n header,\n footer,\n visible = false,\n locale = defaultLocale,\n onClose = () => {},\n onOk,\n size,\n id,\n onClick = () => {},\n children,\n ...rest\n },\n ref\n ) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const { theme } = useTheme();\n const mounted = useClosable(visible, theme.transitionDelay);\n useBodyScroll(!visible);\n useKeyPress(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'Escape',\n onClose\n );\n\n const titleId = useMemo(\n () => `modal-title-${Math.random().toString(36).slice(2, 11)}`,\n []\n );\n const bodyId = useMemo(\n () => id || `modal-body-${Math.random().toString(36).slice(2, 11)}`,\n [id]\n );\n\n if (!mounted) return null;\n\n return (\n <Portal>\n <ModalMask visible={visible} />\n <Container onClick={onClose}>\n <FocusLock autoFocus={false}>\n <Content\n visible={visible}\n size={size}\n onClick={(e) => {\n e.stopPropagation();\n onClick(e);\n }}\n role='dialog'\n aria-modal\n aria-labelledby={header === undefined ? titleId : undefined}\n aria-describedby={bodyId}\n ref={contentRef}\n >\n {header === undefined ? (\n <ThemeOverrider\n overrides={(t) => ({\n buttonPaddingHorizontal:\n t.modalCloseButtonPaddingHorizontal,\n })}\n >\n <Header>\n <Title id={titleId}>{title}</Title>\n <Button\n type='ghost'\n wide='never'\n onClick={onClose}\n aria-label={locale.closeLabel}\n >\n <Close />\n </Button>\n </Header>\n </ThemeOverrider>\n ) : (\n header\n )}\n\n <Body id={bodyId} {...rest} ref={ref}>\n {children}\n </Body>\n\n {footer === undefined ? (\n <Footer>\n <Button\n danger={okDanger}\n loading={okLoading}\n disabled={okDisabled}\n onClick={onOk}\n >\n {okText}\n </Button>\n </Footer>\n ) : (\n footer\n )}\n </Content>\n </FocusLock>\n </Container>\n </Portal>\n );\n }\n);\n\nModal.displayName = 'Modal';\n\nexport default Modal;\n"],"file":"index.js"}
|
|
@@ -6,8 +6,26 @@ import { omitEmotionProps, useForwardedState } from '@os-design/utils';
|
|
|
6
6
|
import styled from '@emotion/styled';
|
|
7
7
|
import { m } from '@os-design/media';
|
|
8
8
|
import { clr } from '@os-design/theming';
|
|
9
|
+
import { css } from '@emotion/react';
|
|
9
10
|
import Button from '../Button';
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
const wideDefaultStyles = p => p.wide === 'default' && css`
|
|
13
|
+
${m.max.xxs} {
|
|
14
|
+
width: 100%;
|
|
15
|
+
& > button {
|
|
16
|
+
flex: 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
const wideAlwaysStyles = p => p.wide === 'always' && css`
|
|
22
|
+
width: 100%;
|
|
23
|
+
& > button {
|
|
24
|
+
flex: 1;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const Container = styled('div', omitEmotionProps('wide', 'disabled', 'size'))`
|
|
11
29
|
display: inline-flex;
|
|
12
30
|
flex-wrap: wrap;
|
|
13
31
|
|
|
@@ -16,13 +34,8 @@ const Container = styled('div', omitEmotionProps('disabled', 'size'))`
|
|
|
16
34
|
border: 1px solid
|
|
17
35
|
${p => p.disabled ? clr(p.theme.buttonDisabledGhostColorText) : clr(p.theme.colorPrimary)};
|
|
18
36
|
|
|
19
|
-
${
|
|
20
|
-
|
|
21
|
-
& > button {
|
|
22
|
-
flex: 1;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
37
|
+
${wideDefaultStyles};
|
|
38
|
+
${wideAlwaysStyles};
|
|
26
39
|
${sizeStyles};
|
|
27
40
|
`;
|
|
28
41
|
const StyledButton = styled(Button)`
|
|
@@ -34,6 +47,7 @@ const StyledButton = styled(Button)`
|
|
|
34
47
|
|
|
35
48
|
const RadioGroup = /*#__PURE__*/forwardRef(({
|
|
36
49
|
options = [],
|
|
50
|
+
wide = 'default',
|
|
37
51
|
disabled = false,
|
|
38
52
|
value,
|
|
39
53
|
defaultValue,
|
|
@@ -47,6 +61,7 @@ const RadioGroup = /*#__PURE__*/forwardRef(({
|
|
|
47
61
|
onChange
|
|
48
62
|
});
|
|
49
63
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Container, _extends({
|
|
64
|
+
wide: wide,
|
|
50
65
|
disabled: disabled,
|
|
51
66
|
size: size
|
|
52
67
|
}, rest, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/RadioGroup/index.tsx"],"names":["React","forwardRef","sizeStyles","omitEmotionProps","useForwardedState","styled","m","clr","Button","
|
|
1
|
+
{"version":3,"sources":["../../../src/RadioGroup/index.tsx"],"names":["React","forwardRef","sizeStyles","omitEmotionProps","useForwardedState","styled","m","clr","css","Button","wideDefaultStyles","p","wide","max","xxs","wideAlwaysStyles","Container","theme","borderRadius","disabled","buttonDisabledGhostColorText","colorPrimary","StyledButton","RadioGroup","options","value","defaultValue","onChange","size","rest","ref","forwardedValue","setForwardedValue","map","title","valueOption","disabledOption","onClick","buttonRest","e","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,QAAkC,OAAlC;AACA,SAASC,UAAT,QAAqC,mBAArC;AACA,SAASC,gBAAT,EAA2BC,iBAA3B,QAAoD,kBAApD;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,CAAT,QAAkB,kBAAlB;AACA,SAASC,GAAT,QAAoB,oBAApB;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,OAAOC,MAAP,MAAoC,WAApC;;AAuDA,MAAMC,iBAAiB,GAAIC,CAAD,IACxBA,CAAC,CAAC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IAAA,IAAI,EAAEf,IADR;AAEE,IAAA,QAAQ,EAAEO,QAFZ;AAGE,IAAA,IAAI,EAAES;AAHR,KAIMC,IAJN;AAKE,IAAA,GAAG,EAAEC;AALP,MAOGN,OAAO,EAAES,GAAT,CACC,CAAC;AACCC,IAAAA,KADD;AAECT,IAAAA,KAAK,EAAEU,WAFR;AAGChB,IAAAA,QAAQ,EAAEiB,cAHX;AAICC,IAAAA,OAAO,GAAG,MAAM,CAAE,CAJnB;AAKC,OAAGC;AALJ,GAAD,kBAOE,oBAAC,YAAD;AACE,IAAA,GAAG,EAAEH,WADP;AAEE,IAAA,IAAI,EAAEJ,cAAc,KAAKI,WAAnB,GAAiC,SAAjC,GAA6C,OAFrD;AAGE,IAAA,IAAI,EAAC,OAHP;AAIE,IAAA,QAAQ,EAAEhB,QAAQ,IAAIiB,cAJxB;AAKE,IAAA,OAAO,EAAGG,CAAD,IAAO;AACdP,MAAAA,iBAAiB,CAACG,WAAD,CAAjB;AACAE,MAAAA,OAAO,CAACE,CAAD,CAAP;AACD;AARH,KASMD,UATN,GAWGJ,KAXH,CARH,CAPH,CADF,CADF;AAmCD,CAvD0B,CAA7B;AA0DAX,UAAU,CAACiB,WAAX,GAAyB,YAAzB;AAEA,eAAejB,UAAf","sourcesContent":["import React, { forwardRef } from 'react';\nimport { sizeStyles, WithSize } from '@os-design/styles';\nimport { omitEmotionProps, useForwardedState } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { m } from '@os-design/media';\nimport { clr } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport Button, { ButtonProps } from '../Button';\n\nexport interface RadioGroupOption\n extends Omit<ButtonProps, 'type' | 'wide' | 'size'> {\n /**\n * The title of the option.\n */\n title: string;\n /**\n * The value of the option.\n */\n value: string;\n}\n\ntype JsxDivProps = Omit<\n JSX.IntrinsicElements['div'],\n 'value' | 'defaultValue' | 'onChange' | 'ref'\n>;\nexport interface RadioGroupProps extends JsxDivProps, WithSize {\n /**\n * Options of the radio group.\n * @default undefined\n */\n options?: RadioGroupOption[];\n /**\n * Whether the radio group has full width.\n * Possible values:\n * `default` – the radio group has full width if the screen width is less than xs;\n * `always` – the radio group always has full width;\n * `never` – the radio group never has full width.\n * @default default\n */\n wide?: 'default' | 'always' | 'never';\n /**\n * Whether the radio group is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Selected option.\n * @default false\n */\n value?: string;\n /**\n * The default value.\n * @default undefined\n */\n defaultValue?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string) => void;\n}\n\nconst wideDefaultStyles = (p) =>\n p.wide === 'default' &&\n css`\n ${m.max.xxs} {\n width: 100%;\n & > button {\n flex: 1;\n }\n }\n `;\n\nconst wideAlwaysStyles = (p) =>\n p.wide === 'always' &&\n css`\n width: 100%;\n & > button {\n flex: 1;\n }\n `;\n\ntype ContainerProps = Required<Pick<RadioGroupProps, 'wide' | 'disabled'>> &\n WithSize;\nconst Container = styled(\n 'div',\n omitEmotionProps('wide', 'disabled', 'size')\n)<ContainerProps>`\n display: inline-flex;\n flex-wrap: wrap;\n\n border-radius: ${(p) => p.theme.borderRadius}em;\n overflow: hidden;\n border: 1px solid\n ${(p) =>\n p.disabled\n ? clr(p.theme.buttonDisabledGhostColorText)\n : clr(p.theme.colorPrimary)};\n\n ${wideDefaultStyles};\n ${wideAlwaysStyles};\n ${sizeStyles};\n`;\n\nconst StyledButton = styled(Button)`\n border-radius: 0;\n`;\n\n/**\n * The radio buttons that allow a user to select only one of a limited number of options.\n */\nconst RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(\n (\n {\n options = [],\n wide = 'default',\n disabled = false,\n value,\n defaultValue,\n onChange = () => {},\n size,\n ...rest\n },\n ref\n ) => {\n const [forwardedValue, setForwardedValue] = useForwardedState({\n value,\n defaultValue,\n onChange,\n });\n\n return (\n <div>\n <Container\n wide={wide}\n disabled={disabled}\n size={size}\n {...rest}\n ref={ref}\n >\n {options?.map(\n ({\n title,\n value: valueOption,\n disabled: disabledOption,\n onClick = () => {},\n ...buttonRest\n }) => (\n <StyledButton\n key={valueOption}\n type={forwardedValue === valueOption ? 'primary' : 'ghost'}\n wide='never'\n disabled={disabled || disabledOption}\n onClick={(e) => {\n setForwardedValue(valueOption);\n onClick(e);\n }}\n {...buttonRest}\n >\n {title}\n </StyledButton>\n )\n )}\n </Container>\n </div>\n );\n }\n);\n\nRadioGroup.displayName = 'RadioGroup';\n\nexport default RadioGroup;\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Input/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,YAAY,EAAuB,MAAM,OAAO,CAAC;AAC9E,OAAO,EAIL,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAQ3B,aAAK,aAAa,GAAG,IAAI,CACvB,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAC9B,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,CACtC,CAAC;AACF,MAAM,WAAW,UAAW,SAAQ,aAAa,EAAE,QAAQ;IAKzD,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAK7B,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAMvB,cAAc,CAAC,EAAE,OAAO,CAAC;IAKzB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAMxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAK1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAKlB,YAAY,CAAC,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IAK5C,cAAc,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAK9C,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,E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AAK,IAAI,CAAC;CACtE;AAuCD,eAAO,MAAM,cAAc;;;6HAqB1B,CAAC;AAcF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AACD,eAAO,MAAM,WAAW;;;iHAoBvB,CAAC;AAqCF,QAAA,MAAM,KAAK,qFA+FV,CAAC;AAIF,eAAe,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Modal/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Modal/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAS3D,OAAO,EAIL,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAO3B,OAAsB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEnE,aAAK,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAC7D,MAAM,WAAW,UAAW,SAAQ,WAAW,EAAE,QAAQ;IAKvD,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,SAAS,CAAC,EAAE,OAAO,CAAC;IAKpB,UAAU,CAAC,EAAE,OAAO,CAAC;IAMrB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAMzB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAKzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAKlB,MAAM,CAAC,EAAE,WAAW,CAAC;IAMrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAKrB,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;CACnB;AA4BD,eAAO,MAAM,SAAS;;;mHAUrB,CAAC;AAuJF,QAAA,MAAM,KAAK,mFA4GV,CAAC;AAIF,eAAe,KAAK,CAAC"}
|
|
@@ -8,6 +8,7 @@ export interface RadioGroupOption extends Omit<ButtonProps, 'type' | 'wide' | 's
|
|
|
8
8
|
declare type JsxDivProps = Omit<JSX.IntrinsicElements['div'], 'value' | 'defaultValue' | 'onChange' | 'ref'>;
|
|
9
9
|
export interface RadioGroupProps extends JsxDivProps, WithSize {
|
|
10
10
|
options?: RadioGroupOption[];
|
|
11
|
+
wide?: 'default' | 'always' | 'never';
|
|
11
12
|
disabled?: boolean;
|
|
12
13
|
value?: string;
|
|
13
14
|
defaultValue?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/RadioGroup/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAc,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/RadioGroup/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAc,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAMzD,OAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAInD,KAAK,EAAE,MAAM,CAAC;IAId,KAAK,EAAE,MAAM,CAAC;CACf;AAED,aAAK,WAAW,GAAG,IAAI,CACrB,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAC5B,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,KAAK,CAC9C,CAAC;AACF,MAAM,WAAW,eAAgB,SAAQ,WAAW,EAAE,QAAQ;IAK5D,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAS7B,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IAKtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAmDD,QAAA,MAAM,UAAU,wFAwDf,CAAC;AAIF,eAAe,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.132",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"react": ">=18",
|
|
57
57
|
"react-dom": ">=18"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "d81c7eedcdf14120ac9d0fa830a5eeb83abf01ac"
|
|
60
60
|
}
|