@os-design/core 1.0.229 → 1.0.231
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/ButtonContent.js +1 -1
- package/dist/cjs/Button/ButtonContent.js.map +1 -1
- package/dist/cjs/Button/index.js +2 -2
- package/dist/cjs/Button/index.js.map +1 -1
- package/dist/cjs/Button/utils/useButtonColors.js +1 -1
- package/dist/cjs/Button/utils/useButtonColors.js.map +1 -1
- package/dist/cjs/ButtonLink/index.js +94 -0
- package/dist/cjs/ButtonLink/index.js.map +1 -0
- package/dist/cjs/Link/index.js +20 -18
- package/dist/cjs/Link/index.js.map +1 -1
- package/dist/cjs/LinkButton/index.js +22 -50
- package/dist/cjs/LinkButton/index.js.map +1 -1
- package/dist/cjs/Select/index.js +2 -2
- package/dist/cjs/Select/index.js.map +1 -1
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Button/ButtonContent.js +1 -1
- package/dist/esm/Button/ButtonContent.js.map +1 -1
- package/dist/esm/Button/index.js +2 -2
- package/dist/esm/Button/index.js.map +1 -1
- package/dist/esm/Button/utils/useButtonColors.js +1 -1
- package/dist/esm/Button/utils/useButtonColors.js.map +1 -1
- package/dist/esm/ButtonLink/index.js +78 -0
- package/dist/esm/ButtonLink/index.js.map +1 -0
- package/dist/esm/Link/index.js +36 -23
- package/dist/esm/Link/index.js.map +1 -1
- package/dist/esm/LinkButton/index.js +29 -47
- package/dist/esm/LinkButton/index.js.map +1 -1
- package/dist/esm/Select/index.js +2 -2
- package/dist/esm/Select/index.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/ButtonLink/index.d.ts +286 -0
- package/dist/types/ButtonLink/index.d.ts.map +1 -0
- package/dist/types/Link/index.d.ts +7 -0
- package/dist/types/Link/index.d.ts.map +1 -1
- package/dist/types/LinkButton/index.d.ts +7 -283
- package/dist/types/LinkButton/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Button/ButtonContent.tsx +1 -1
- package/src/Button/index.tsx +2 -2
- package/src/Button/utils/useButtonColors.ts +1 -1
- package/src/ButtonLink/index.tsx +102 -0
- package/src/Link/index.tsx +57 -24
- package/src/LinkButton/index.tsx +50 -62
- package/src/Select/index.tsx +2 -2
- package/src/index.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["css","styled","m","resetButtonStyles","sizeStyles","transitionStyles","clr","omitEmotionProps","React","forwardRef","ButtonContent","useButtonColors","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","createElement","_extends","e","preventDefault","displayName"],"sources":["../../../src/Button/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport { m } from '@os-design/media';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { clr } from '@os-design/theming';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\nimport ButtonContent from './ButtonContent';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button,
|
|
1
|
+
{"version":3,"file":"index.js","names":["css","styled","m","resetButtonStyles","sizeStyles","transitionStyles","clr","omitEmotionProps","React","forwardRef","ButtonContent","useButtonColors","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","createElement","_extends","e","preventDefault","displayName"],"sources":["../../../src/Button/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport { m } from '@os-design/media';\nimport {\n resetButtonStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { clr } from '@os-design/theming';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\nimport ButtonContent from './ButtonContent';\nimport useButtonColors, { ButtonColors } from './utils/useButtonColors';\n\ntype JsxButtonProps = Omit<\n JSX.IntrinsicElements['button'],\n 'type' | 'color' | 'ref'\n>;\n\n// Used by Button, ButtonLink\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 ButtonLink\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"],"mappings":";AAAA,SAASA,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,CAAC,QAAQ,kBAAkB;AACpC,SACEC,iBAAiB,EACjBC,UAAU,EACVC,gBAAgB,QAEX,mBAAmB;AAC1B,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,eAAe,MAAwB,yBAAyB;;AAOvE;;AAmDA,MAAMC,WAAW,GAAIC,CAAC,IACpB,CAACA,CAAC,CAACC,QAAQ,IACXd,GAAI;AACN;AACA;AACA;AACA,4BAA4BM,GAAG,CAACO,CAAC,CAACE,MAAM,CAACC,OAAO,CAAE;AAClD;AACA;AACA,GAAG;AAEH,MAAMC,aAAa,GAAIJ,CAAC,IACtBA,CAAC,CAACK,OAAO,KAAK,SAAS,IACvBlB,GAAI;AACN,aAAaM,GAAG,CAACO,CAAC,CAACE,MAAM,CAACI,IAAI,CAAE;AAChC,wBAAwBb,GAAG,CAACO,CAAC,CAACE,MAAM,CAACK,EAAE,CAAE;AACzC,MAAMR,WAAW,CAACC,CAAC,CAAE;AACrB,GAAG;AAEH,MAAMQ,WAAW,GAAIR,CAAC,IACpBA,CAAC,CAACK,OAAO,KAAK,OAAO,IACrBlB,GAAI;AACN,aAAaM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","names":["useTheme","useMemo","useButtonColors","type","danger","disabled","theme","prefix","buttonColors","text","bg","bgHover","buttonDisabledPrimaryColorText","buttonDisabledPrimaryColorBg","buttonDisabledGhostColorText","loadingColors"],"sources":["../../../../src/Button/utils/useButtonColors.ts"],"sourcesContent":["import { Color, useTheme } from '@os-design/theming';\nimport { useMemo } from 'react';\n\ninterface Props {\n type: 'primary' | 'outline' | 'ghost';\n danger: boolean;\n disabled: boolean;\n}\n\nexport interface ButtonColors {\n text: Color;\n bg?: Color;\n bgHover?: Color;\n}\n\nexport interface LoadingColors {\n text: Color;\n bg: Color;\n}\n\ninterface UseButtonColorsRes {\n buttonColors: ButtonColors;\n loadingColors: LoadingColors;\n}\n\n// Used by Button,
|
|
1
|
+
{"version":3,"file":"useButtonColors.js","names":["useTheme","useMemo","useButtonColors","type","danger","disabled","theme","prefix","buttonColors","text","bg","bgHover","buttonDisabledPrimaryColorText","buttonDisabledPrimaryColorBg","buttonDisabledGhostColorText","loadingColors"],"sources":["../../../../src/Button/utils/useButtonColors.ts"],"sourcesContent":["import { Color, useTheme } from '@os-design/theming';\nimport { useMemo } from 'react';\n\ninterface Props {\n type: 'primary' | 'outline' | 'ghost';\n danger: boolean;\n disabled: boolean;\n}\n\nexport interface ButtonColors {\n text: Color;\n bg?: Color;\n bgHover?: Color;\n}\n\nexport interface LoadingColors {\n text: Color;\n bg: Color;\n}\n\ninterface UseButtonColorsRes {\n buttonColors: ButtonColors;\n loadingColors: LoadingColors;\n}\n\n// Used by Button, ButtonLink\nconst useButtonColors = ({\n type,\n danger,\n disabled,\n}: Props): UseButtonColorsRes => {\n const { theme } = useTheme();\n\n const prefix = useMemo<string>(() => {\n if (danger) return 'Danger';\n return '';\n }, [danger]);\n\n const buttonColors = useMemo<ButtonColors>(() => {\n if (type === 'primary') {\n return !disabled\n ? {\n text: theme[`button${prefix}PrimaryColorText`],\n bg: theme[`button${prefix}PrimaryColorBg`],\n bgHover: theme[`button${prefix}PrimaryColorBgHover`],\n }\n : {\n text: theme.buttonDisabledPrimaryColorText,\n bg: theme.buttonDisabledPrimaryColorBg,\n };\n }\n return !disabled\n ? {\n text: theme[`button${prefix}GhostColorText`],\n bgHover: theme[`button${prefix}GhostColorBgHover`],\n }\n : {\n text: theme.buttonDisabledGhostColorText,\n };\n }, [type, disabled, theme, prefix]);\n\n const loadingColors = useMemo<LoadingColors>(() => {\n if (disabled) {\n return {\n text: theme.buttonDisabledPrimaryColorText,\n bg: theme.buttonDisabledPrimaryColorBg,\n };\n }\n if (type === 'primary') {\n return {\n text: theme[`button${prefix}PrimaryColorLoadingText`],\n bg: theme[`button${prefix}PrimaryColorLoadingBg`],\n };\n }\n return {\n text: theme[`button${prefix}GhostColorLoadingText`],\n bg: theme[`button${prefix}GhostColorLoadingBg`],\n };\n }, [disabled, type, theme, prefix]);\n\n return { buttonColors, loadingColors };\n};\n\nexport default useButtonColors;\n"],"mappings":"AAAA,SAAgBA,QAAQ,QAAQ,oBAAoB;AACpD,SAASC,OAAO,QAAQ,OAAO;AAwB/B;AACA,MAAMC,eAAe,GAAGA,CAAC;EACvBC,IAAI;EACJC,MAAM;EACNC;AACK,CAAC,KAAyB;EAC/B,MAAM;IAAEC;EAAM,CAAC,GAAGN,QAAQ,CAAC,CAAC;EAE5B,MAAMO,MAAM,GAAGN,OAAO,CAAS,MAAM;IACnC,IAAIG,MAAM,EAAE,OAAO,QAAQ;IAC3B,OAAO,EAAE;EACX,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,MAAMI,YAAY,GAAGP,OAAO,CAAe,MAAM;IAC/C,IAAIE,IAAI,KAAK,SAAS,EAAE;MACtB,OAAO,CAACE,QAAQ,GACZ;QACEI,IAAI,EAAEH,KAAK,CAAE,SAAQC,MAAO,kBAAiB,CAAC;QAC9CG,EAAE,EAAEJ,KAAK,CAAE,SAAQC,MAAO,gBAAe,CAAC;QAC1CI,OAAO,EAAEL,KAAK,CAAE,SAAQC,MAAO,qBAAoB;MACrD,CAAC,GACD;QACEE,IAAI,EAAEH,KAAK,CAACM,8BAA8B;QAC1CF,EAAE,EAAEJ,KAAK,CAACO;MACZ,CAAC;IACP;IACA,OAAO,CAACR,QAAQ,GACZ;MACEI,IAAI,EAAEH,KAAK,CAAE,SAAQC,MAAO,gBAAe,CAAC;MAC5CI,OAAO,EAAEL,KAAK,CAAE,SAAQC,MAAO,mBAAkB;IACnD,CAAC,GACD;MACEE,IAAI,EAAEH,KAAK,CAACQ;IACd,CAAC;EACP,CAAC,EAAE,CAACX,IAAI,EAAEE,QAAQ,EAAEC,KAAK,EAAEC,MAAM,CAAC,CAAC;EAEnC,MAAMQ,aAAa,GAAGd,OAAO,CAAgB,MAAM;IACjD,IAAII,QAAQ,EAAE;MACZ,OAAO;QACLI,IAAI,EAAEH,KAAK,CAACM,8BAA8B;QAC1CF,EAAE,EAAEJ,KAAK,CAACO;MACZ,CAAC;IACH;IACA,IAAIV,IAAI,KAAK,SAAS,EAAE;MACtB,OAAO;QACLM,IAAI,EAAEH,KAAK,CAAE,SAAQC,MAAO,yBAAwB,CAAC;QACrDG,EAAE,EAAEJ,KAAK,CAAE,SAAQC,MAAO,uBAAsB;MAClD,CAAC;IACH;IACA,OAAO;MACLE,IAAI,EAAEH,KAAK,CAAE,SAAQC,MAAO,uBAAsB,CAAC;MACnDG,EAAE,EAAEJ,KAAK,CAAE,SAAQC,MAAO,qBAAoB;IAChD,CAAC;EACH,CAAC,EAAE,CAACF,QAAQ,EAAEF,IAAI,EAAEG,KAAK,EAAEC,MAAM,CAAC,CAAC;EAEnC,OAAO;IAAEC,YAAY;IAAEO;EAAc,CAAC;AACxC,CAAC;AAED,eAAeb,eAAe"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { css } from '@emotion/react';
|
|
3
|
+
import styled from '@emotion/styled';
|
|
4
|
+
import { omitEmotionProps } from '@os-design/utils';
|
|
5
|
+
import React, { forwardRef } from 'react';
|
|
6
|
+
import { StyledButton } from '../Button';
|
|
7
|
+
import ButtonContent from '../Button/ButtonContent';
|
|
8
|
+
import useButtonColors from '../Button/utils/useButtonColors';
|
|
9
|
+
import { DisabledWrapper } from '../Link';
|
|
10
|
+
const disabledStyles = p => p.disabled && css`
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
`;
|
|
13
|
+
const StyledButtonLink = styled(StyledButton.withComponent('a'), omitEmotionProps('as', 'disabled'))`
|
|
14
|
+
text-decoration: none;
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
${disabledStyles};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The button that is rendered as a link.
|
|
21
|
+
*/
|
|
22
|
+
const ButtonLink = /*#__PURE__*/forwardRef(({
|
|
23
|
+
type = 'primary',
|
|
24
|
+
danger = false,
|
|
25
|
+
left,
|
|
26
|
+
right,
|
|
27
|
+
wide = 'default',
|
|
28
|
+
loading = false,
|
|
29
|
+
disabled = false,
|
|
30
|
+
size,
|
|
31
|
+
as,
|
|
32
|
+
onMouseDown = () => {},
|
|
33
|
+
onKeyDown = () => {},
|
|
34
|
+
children,
|
|
35
|
+
...rest
|
|
36
|
+
}, ref) => {
|
|
37
|
+
const {
|
|
38
|
+
buttonColors,
|
|
39
|
+
loadingColors
|
|
40
|
+
} = useButtonColors({
|
|
41
|
+
type,
|
|
42
|
+
danger,
|
|
43
|
+
disabled
|
|
44
|
+
});
|
|
45
|
+
const link = /*#__PURE__*/React.createElement(StyledButtonLink, _extends({
|
|
46
|
+
btnType: type,
|
|
47
|
+
colors: buttonColors,
|
|
48
|
+
wide: wide,
|
|
49
|
+
loading: loading,
|
|
50
|
+
disabled: disabled || loading,
|
|
51
|
+
size: size,
|
|
52
|
+
as: as,
|
|
53
|
+
onMouseDown: e => {
|
|
54
|
+
onMouseDown(e);
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
},
|
|
57
|
+
onKeyDown: e => {
|
|
58
|
+
onKeyDown(e);
|
|
59
|
+
if (disabled || loading) e.preventDefault();
|
|
60
|
+
},
|
|
61
|
+
"aria-disabled": disabled || loading,
|
|
62
|
+
"aria-busy": loading
|
|
63
|
+
}, rest, {
|
|
64
|
+
ref: ref
|
|
65
|
+
}), /*#__PURE__*/React.createElement(ButtonContent, {
|
|
66
|
+
left: left,
|
|
67
|
+
right: right,
|
|
68
|
+
loading: loading,
|
|
69
|
+
loadingColors: loadingColors
|
|
70
|
+
}, children));
|
|
71
|
+
if (disabled || loading) {
|
|
72
|
+
return /*#__PURE__*/React.createElement(DisabledWrapper, null, link);
|
|
73
|
+
}
|
|
74
|
+
return link;
|
|
75
|
+
});
|
|
76
|
+
ButtonLink.displayName = 'ButtonLink';
|
|
77
|
+
export default ButtonLink;
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["css","styled","omitEmotionProps","React","forwardRef","StyledButton","ButtonContent","useButtonColors","DisabledWrapper","disabledStyles","p","disabled","StyledButtonLink","withComponent","ButtonLink","type","danger","left","right","wide","loading","size","as","onMouseDown","onKeyDown","children","rest","ref","buttonColors","loadingColors","link","createElement","_extends","btnType","colors","e","preventDefault","displayName"],"sources":["../../../src/ButtonLink/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\nimport { ButtonProps, StyledButton } from '../Button';\nimport ButtonContent from '../Button/ButtonContent';\nimport useButtonColors from '../Button/utils/useButtonColors';\nimport { DisabledWrapper, LinkProps, ReactRouterLinkProps } from '../Link';\n\ntype JsxAProps = Omit<JSX.IntrinsicElements['a'], 'type' | 'ref'>;\nexport type ButtonLinkProps = JsxAProps &\n ReactRouterLinkProps &\n Pick<LinkProps, 'as'> &\n ButtonProps;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n pointer-events: none;\n `;\n\nconst StyledButtonLink = styled(\n StyledButton.withComponent('a'),\n omitEmotionProps('as', 'disabled')\n)`\n text-decoration: none;\n display: inline-flex;\n ${disabledStyles};\n`;\n\n/**\n * The button that is rendered as a link.\n */\nconst ButtonLink = forwardRef<HTMLAnchorElement, ButtonLinkProps>(\n (\n {\n type = 'primary',\n danger = false,\n left,\n right,\n wide = 'default',\n loading = false,\n disabled = false,\n size,\n as,\n onMouseDown = () => {},\n onKeyDown = () => {},\n children,\n ...rest\n },\n ref\n ) => {\n const { buttonColors, loadingColors } = useButtonColors({\n type,\n danger,\n disabled,\n });\n\n const link = (\n <StyledButtonLink\n btnType={type}\n colors={buttonColors}\n wide={wide}\n loading={loading}\n disabled={disabled || loading}\n size={size}\n as={as}\n onMouseDown={(e) => {\n onMouseDown(e);\n e.preventDefault();\n }}\n onKeyDown={(e) => {\n onKeyDown(e);\n if (disabled || loading) e.preventDefault();\n }}\n aria-disabled={disabled || loading}\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 </StyledButtonLink>\n );\n\n if (disabled || loading) {\n return <DisabledWrapper>{link}</DisabledWrapper>;\n }\n\n return link;\n }\n);\n\nButtonLink.displayName = 'ButtonLink';\n\nexport default ButtonLink;\n"],"mappings":";AAAA,SAASA,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,SAAsBC,YAAY,QAAQ,WAAW;AACrD,OAAOC,aAAa,MAAM,yBAAyB;AACnD,OAAOC,eAAe,MAAM,iCAAiC;AAC7D,SAASC,eAAe,QAAyC,SAAS;AAQ1E,MAAMC,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,CAAC,CAACC,cAAc,CAAC,CAAC;IAC7C,CAAE;IACF,iBAAezB,QAAQ,IAAIS,OAAQ;IACnC,aAAWA;EAAQ,GACfM,IAAI;IACRC,GAAG,EAAEA;EAAI,iBAETxB,KAAA,CAAA4B,aAAA,CAACzB,aAAa;IACZW,IAAI,EAAEA,IAAK;IACXC,KAAK,EAAEA,KAAM;IACbE,OAAO,EAAEA,OAAQ;IACjBS,aAAa,EAAEA;EAAc,GAE5BJ,QACY,CACC,CACnB;EAED,IAAId,QAAQ,IAAIS,OAAO,EAAE;IACvB,oBAAOjB,KAAA,CAAA4B,aAAA,CAACvB,eAAe,QAAEsB,IAAsB,CAAC;EAClD;EAEA,OAAOA,IAAI;AACb,CACF,CAAC;AAEDhB,UAAU,CAACuB,WAAW,GAAG,YAAY;AAErC,eAAevB,UAAU"}
|
package/dist/esm/Link/index.js
CHANGED
|
@@ -5,9 +5,6 @@ import { resetFocusStyles, sizeStyles, transitionStyles } from '@os-design/style
|
|
|
5
5
|
import { clr } from '@os-design/theming';
|
|
6
6
|
import { omitEmotionProps } from '@os-design/utils';
|
|
7
7
|
import React, { forwardRef } from 'react';
|
|
8
|
-
/**
|
|
9
|
-
* Sets base underline styles.
|
|
10
|
-
*/
|
|
11
8
|
const underlineBaseStyles = p => css`
|
|
12
9
|
position: relative;
|
|
13
10
|
display: inline-block;
|
|
@@ -22,11 +19,7 @@ const underlineBaseStyles = p => css`
|
|
|
22
19
|
background-color: ${clr(p.theme.linkColor)};
|
|
23
20
|
}
|
|
24
21
|
`;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sets underline styles on hover.
|
|
28
|
-
*/
|
|
29
|
-
const underlineHoverStyles = p => p.underline === 'hover' && css`
|
|
22
|
+
export const underlineHoverStyles = p => p.underline === 'hover' && css`
|
|
30
23
|
@media (hover: hover) {
|
|
31
24
|
${underlineBaseStyles(p)};
|
|
32
25
|
|
|
@@ -43,11 +36,7 @@ const underlineHoverStyles = p => p.underline === 'hover' && css`
|
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
38
|
`;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Sets underline styles always.
|
|
49
|
-
*/
|
|
50
|
-
const underlineAlwaysStyles = p => p.underline === 'always' && css`
|
|
39
|
+
export const underlineAlwaysStyles = p => p.underline === 'always' && css`
|
|
51
40
|
${underlineBaseStyles(p)};
|
|
52
41
|
|
|
53
42
|
&::after {
|
|
@@ -55,7 +44,20 @@ const underlineAlwaysStyles = p => p.underline === 'always' && css`
|
|
|
55
44
|
opacity: 1;
|
|
56
45
|
}
|
|
57
46
|
`;
|
|
58
|
-
const
|
|
47
|
+
const disabledStyles = p => p.disabled && css`
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
|
|
50
|
+
&,
|
|
51
|
+
&:active,
|
|
52
|
+
&:focus {
|
|
53
|
+
color: ${clr(p.theme.inputColorPlaceholder)};
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
export const DisabledWrapper = styled.div`
|
|
57
|
+
display: inline-block;
|
|
58
|
+
cursor: not-allowed;
|
|
59
|
+
`;
|
|
60
|
+
const StyledLink = styled('a', omitEmotionProps('size', 'underline', 'disabled', 'as'))`
|
|
59
61
|
${resetFocusStyles};
|
|
60
62
|
|
|
61
63
|
cursor: pointer;
|
|
@@ -70,6 +72,7 @@ const StyledLink = styled('a', omitEmotionProps('size', 'underline', 'as'))`
|
|
|
70
72
|
|
|
71
73
|
${underlineHoverStyles};
|
|
72
74
|
${underlineAlwaysStyles};
|
|
75
|
+
${disabledStyles};
|
|
73
76
|
${sizeStyles};
|
|
74
77
|
`;
|
|
75
78
|
|
|
@@ -78,19 +81,29 @@ const StyledLink = styled('a', omitEmotionProps('size', 'underline', 'as'))`
|
|
|
78
81
|
*/
|
|
79
82
|
const Link = /*#__PURE__*/forwardRef(({
|
|
80
83
|
underline = 'hover',
|
|
84
|
+
disabled = false,
|
|
81
85
|
as,
|
|
82
86
|
onMouseDown = () => {},
|
|
83
87
|
...rest
|
|
84
|
-
}, ref) =>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
}, ref) => {
|
|
89
|
+
if (disabled) {
|
|
90
|
+
return /*#__PURE__*/React.createElement(DisabledWrapper, null, /*#__PURE__*/React.createElement(StyledLink, _extends({
|
|
91
|
+
disabled: true
|
|
92
|
+
}, rest, {
|
|
93
|
+
ref: ref
|
|
94
|
+
})));
|
|
90
95
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
return /*#__PURE__*/React.createElement(StyledLink, _extends({
|
|
97
|
+
underline: underline,
|
|
98
|
+
as: as,
|
|
99
|
+
onMouseDown: e => {
|
|
100
|
+
onMouseDown(e);
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
}
|
|
103
|
+
}, rest, {
|
|
104
|
+
ref: ref
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
94
107
|
Link.displayName = 'Link';
|
|
95
108
|
export default Link;
|
|
96
109
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["css","styled","resetFocusStyles","sizeStyles","transitionStyles","clr","omitEmotionProps","React","forwardRef","underlineBaseStyles","p","theme","linkColor","underlineHoverStyles","underline","underlineAlwaysStyles","StyledLink","Link","as","onMouseDown","rest","ref","createElement","_extends","e","preventDefault","displayName"],"sources":["../../../src/Link/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { clr } from '@os-design/theming';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\n\nexport interface ReactRouterLinkProps {\n to?: string;\n replace?: boolean;\n}\n\ntype JsxAProps = Omit<JSX.IntrinsicElements['a'], 'ref'>;\nexport interface LinkProps extends JsxAProps, ReactRouterLinkProps, WithSize {\n /**\n * Type of the underline styles.\n * @default hover\n */\n underline?: 'hover' | 'always' | 'never';\n /**\n * The custom link component.\n * For example, the Link from react-router-dom.\n * @default undefined\n */\n as?: React.ElementType;\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["css","styled","resetFocusStyles","sizeStyles","transitionStyles","clr","omitEmotionProps","React","forwardRef","underlineBaseStyles","p","theme","linkColor","underlineHoverStyles","underline","underlineAlwaysStyles","disabledStyles","disabled","inputColorPlaceholder","DisabledWrapper","div","StyledLink","Link","as","onMouseDown","rest","ref","createElement","_extends","e","preventDefault","displayName"],"sources":["../../../src/Link/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { clr } from '@os-design/theming';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\n\nexport interface ReactRouterLinkProps {\n to?: string;\n replace?: boolean;\n}\n\ntype JsxAProps = Omit<JSX.IntrinsicElements['a'], 'ref'>;\nexport interface LinkProps extends JsxAProps, ReactRouterLinkProps, WithSize {\n /**\n * Type of the underline styles.\n * @default hover\n */\n underline?: 'hover' | 'always' | 'never';\n /**\n * Whether the link is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * The custom link component.\n * For example, the Link from react-router-dom.\n * @default undefined\n */\n as?: React.ElementType;\n}\n\nconst underlineBaseStyles = (p) => css`\n position: relative;\n display: inline-block;\n padding-bottom: 0.1em;\n\n &::after {\n position: absolute;\n bottom: 0;\n left: 0;\n content: '';\n height: 0.125em;\n background-color: ${clr(p.theme.linkColor)};\n }\n`;\n\nexport const underlineHoverStyles = (p) =>\n p.underline === 'hover' &&\n css`\n @media (hover: hover) {\n ${underlineBaseStyles(p)};\n\n &::after {\n width: 0;\n opacity: 0;\n ${transitionStyles('width', 'opacity')(p)};\n }\n\n &:hover::after,\n &:focus::after {\n width: 100%;\n opacity: 1;\n }\n }\n `;\n\nexport const underlineAlwaysStyles = (p) =>\n p.underline === 'always' &&\n css`\n ${underlineBaseStyles(p)};\n\n &::after {\n width: 100%;\n opacity: 1;\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n pointer-events: none;\n\n &,\n &:active,\n &:focus {\n color: ${clr(p.theme.inputColorPlaceholder)};\n }\n `;\n\nexport const DisabledWrapper = styled.div`\n display: inline-block;\n cursor: not-allowed;\n`;\n\nconst StyledLink = styled(\n 'a',\n omitEmotionProps('size', 'underline', 'disabled', 'as')\n)<LinkProps>`\n ${resetFocusStyles};\n\n cursor: pointer;\n text-decoration: none;\n line-height: 1.2;\n\n &,\n &:active,\n &:focus {\n color: ${(p) => clr(p.theme.linkColor)};\n }\n\n ${underlineHoverStyles};\n ${underlineAlwaysStyles};\n ${disabledStyles};\n ${sizeStyles};\n`;\n\n/**\n * The link component to navigate between pages.\n */\nconst Link = forwardRef<HTMLAnchorElement, LinkProps>(\n (\n {\n underline = 'hover',\n disabled = false,\n as,\n onMouseDown = () => {},\n ...rest\n },\n ref\n ) => {\n if (disabled) {\n return (\n <DisabledWrapper>\n <StyledLink disabled {...rest} ref={ref} />\n </DisabledWrapper>\n );\n }\n\n return (\n <StyledLink\n underline={underline}\n as={as}\n onMouseDown={(e) => {\n onMouseDown(e);\n e.preventDefault();\n }}\n {...rest}\n ref={ref}\n />\n );\n }\n);\n\nLink.displayName = 'Link';\n\nexport default Link;\n"],"mappings":";AAAA,SAASA,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SACEC,gBAAgB,EAChBC,UAAU,EACVC,gBAAgB,QAEX,mBAAmB;AAC1B,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AA2BzC,MAAMC,mBAAmB,GAAIC,CAAC,IAAKV,GAAI;AACvC;AACA;AACA;AACA;AACA;A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AG,OAAO;EACnBG,QAAQ,GAAG,KAAK;EAChBM,EAAE;EACFC,WAAW,GAAGA,CAAA,KAAM,CAAC,CAAC;EACtB,GAAGC;AACL,CAAC,EACDC,GAAG,KACA;EACH,IAAIT,QAAQ,EAAE;IACZ,oBACEV,KAAA,CAAAoB,aAAA,CAACR,eAAe,qBACdZ,KAAA,CAAAoB,aAAA,CAACN,UAAU,EAAAO,QAAA;MAACX,QAAQ;IAAA,GAAKQ,IAAI;MAAEC,GAAG,EAAEA;IAAI,EAAE,CAC3B,CAAC;EAEtB;EAEA,oBACEnB,KAAA,CAAAoB,aAAA,CAACN,UAAU,EAAAO,QAAA;IACTd,SAAS,EAAEA,SAAU;IACrBS,EAAE,EAAEA,EAAG;IACPC,WAAW,EAAGK,CAAC,IAAK;MAClBL,WAAW,CAACK,CAAC,CAAC;MACdA,CAAC,CAACC,cAAc,CAAC,CAAC;IACpB;EAAE,GACEL,IAAI;IACRC,GAAG,EAAEA;EAAI,EACV,CAAC;AAEN,CACF,CAAC;AAEDJ,IAAI,CAACS,WAAW,GAAG,MAAM;AAEzB,eAAeT,IAAI"}
|
|
@@ -1,72 +1,54 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
import { css } from '@emotion/react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
|
+
import { resetButtonStyles, sizeStyles } from '@os-design/styles';
|
|
5
|
+
import { clr } from '@os-design/theming';
|
|
4
6
|
import { omitEmotionProps } from '@os-design/utils';
|
|
5
7
|
import React, { forwardRef } from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import ButtonContent from '../Button/ButtonContent';
|
|
8
|
-
import useButtonColors from '../Button/utils/useButtonColors';
|
|
8
|
+
import { DisabledWrapper, underlineAlwaysStyles, underlineHoverStyles } from '../Link';
|
|
9
9
|
const disabledStyles = p => p.disabled && css`
|
|
10
|
-
|
|
10
|
+
cursor: inherit;
|
|
11
|
+
color: ${clr(p.theme.inputColorPlaceholder)};
|
|
11
12
|
`;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const StyledButton = styled('button', omitEmotionProps('size', 'underline'))`
|
|
14
|
+
${resetButtonStyles};
|
|
15
|
+
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
text-align: left;
|
|
18
|
+
line-height: 1.2;
|
|
19
|
+
color: ${p => clr(p.theme.linkColor)};
|
|
20
|
+
|
|
21
|
+
${underlineHoverStyles};
|
|
22
|
+
${underlineAlwaysStyles};
|
|
15
23
|
${disabledStyles};
|
|
24
|
+
${sizeStyles};
|
|
16
25
|
`;
|
|
17
26
|
|
|
18
27
|
/**
|
|
19
|
-
* The
|
|
28
|
+
* The link component that is rendered as a button.
|
|
20
29
|
*/
|
|
21
30
|
const LinkButton = /*#__PURE__*/forwardRef(({
|
|
22
|
-
|
|
23
|
-
danger = false,
|
|
24
|
-
left,
|
|
25
|
-
right,
|
|
26
|
-
wide = 'default',
|
|
27
|
-
loading = false,
|
|
31
|
+
underline = 'hover',
|
|
28
32
|
disabled = false,
|
|
29
|
-
size,
|
|
30
|
-
as,
|
|
31
33
|
onMouseDown = () => {},
|
|
32
|
-
onKeyDown = () => {},
|
|
33
|
-
children,
|
|
34
34
|
...rest
|
|
35
35
|
}, ref) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
btnType: type,
|
|
46
|
-
colors: buttonColors,
|
|
47
|
-
wide: wide,
|
|
48
|
-
loading: loading,
|
|
49
|
-
disabled: disabled || loading,
|
|
50
|
-
size: size,
|
|
51
|
-
as: as,
|
|
36
|
+
if (disabled) {
|
|
37
|
+
return /*#__PURE__*/React.createElement(DisabledWrapper, null, /*#__PURE__*/React.createElement(StyledButton, _extends({
|
|
38
|
+
disabled: true
|
|
39
|
+
}, rest, {
|
|
40
|
+
ref: ref
|
|
41
|
+
})));
|
|
42
|
+
}
|
|
43
|
+
return /*#__PURE__*/React.createElement(StyledButton, _extends({
|
|
44
|
+
underline: underline,
|
|
52
45
|
onMouseDown: e => {
|
|
53
46
|
onMouseDown(e);
|
|
54
47
|
e.preventDefault();
|
|
55
|
-
}
|
|
56
|
-
onKeyDown: e => {
|
|
57
|
-
onKeyDown(e);
|
|
58
|
-
if (disabled || loading) e.preventDefault();
|
|
59
|
-
},
|
|
60
|
-
"aria-disabled": disabled || loading,
|
|
61
|
-
"aria-busy": loading
|
|
48
|
+
}
|
|
62
49
|
}, rest, {
|
|
63
50
|
ref: ref
|
|
64
|
-
})
|
|
65
|
-
left: left,
|
|
66
|
-
right: right,
|
|
67
|
-
loading: loading,
|
|
68
|
-
loadingColors: loadingColors
|
|
69
|
-
}, children));
|
|
51
|
+
}));
|
|
70
52
|
});
|
|
71
53
|
LinkButton.displayName = 'LinkButton';
|
|
72
54
|
export default LinkButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["css","styled","
|
|
1
|
+
{"version":3,"file":"index.js","names":["css","styled","resetButtonStyles","sizeStyles","clr","omitEmotionProps","React","forwardRef","DisabledWrapper","underlineAlwaysStyles","underlineHoverStyles","disabledStyles","p","disabled","theme","inputColorPlaceholder","StyledButton","linkColor","LinkButton","underline","onMouseDown","rest","ref","createElement","_extends","e","preventDefault","displayName"],"sources":["../../../src/LinkButton/index.tsx"],"sourcesContent":["import { css } from '@emotion/react';\nimport styled from '@emotion/styled';\nimport { resetButtonStyles, sizeStyles, WithSize } from '@os-design/styles';\nimport { clr } from '@os-design/theming';\nimport { omitEmotionProps } from '@os-design/utils';\nimport React, { forwardRef } from 'react';\nimport {\n DisabledWrapper,\n underlineAlwaysStyles,\n underlineHoverStyles,\n} from '../Link';\n\ntype JsxButtonProps = Omit<JSX.IntrinsicElements['button'], 'ref'>;\n\nexport interface LinkButtonProps extends JsxButtonProps, WithSize {\n /**\n * Type of the underline styles.\n * @default hover\n */\n underline?: 'hover' | 'always' | 'never';\n /**\n * Whether the link is disabled.\n * @default false\n */\n disabled?: boolean;\n}\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: inherit;\n color: ${clr(p.theme.inputColorPlaceholder)};\n `;\n\nconst StyledButton = styled(\n 'button',\n omitEmotionProps('size', 'underline')\n)<LinkButtonProps>`\n ${resetButtonStyles};\n\n cursor: pointer;\n text-align: left;\n line-height: 1.2;\n color: ${(p) => clr(p.theme.linkColor)};\n\n ${underlineHoverStyles};\n ${underlineAlwaysStyles};\n ${disabledStyles};\n ${sizeStyles};\n`;\n\n/**\n * The link component that is rendered as a button.\n */\nconst LinkButton = forwardRef<HTMLButtonElement, LinkButtonProps>(\n (\n { underline = 'hover', disabled = false, onMouseDown = () => {}, ...rest },\n ref\n ) => {\n if (disabled) {\n return (\n <DisabledWrapper>\n <StyledButton disabled {...rest} ref={ref} />\n </DisabledWrapper>\n );\n }\n\n return (\n <StyledButton\n underline={underline}\n onMouseDown={(e) => {\n onMouseDown(e);\n e.preventDefault();\n }}\n {...rest}\n ref={ref}\n />\n );\n }\n);\n\nLinkButton.displayName = 'LinkButton';\n\nexport default LinkButton;\n"],"mappings":";AAAA,SAASA,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,iBAAiB,EAAEC,UAAU,QAAkB,mBAAmB;AAC3E,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,SACEC,eAAe,EACfC,qBAAqB,EACrBC,oBAAoB,QACf,SAAS;AAiBhB,MAAMC,cAAc,GAAIC,CAAC,IACvBA,CAAC,CAACC,QAAQ,IACVb,GAAI;AACN;AACA,aAAaI,GAAG,CAACQ,CAAC,CAACE,KAAK,CAACC,qBAAqB,CAAE;AAChD,GAAG;AAEH,MAAMC,YAAY,GAAGf,MAAM,CACzB,QAAQ,EACRI,gBAAgB,CAAC,MAAM,EAAE,WAAW,CACtC,CAAmB;AACnB,IAAIH,iBAAkB;AACtB;AACA;AACA;AACA;AACA,WAAYU,CAAC,IAAKR,GAAG,CAACQ,CAAC,CAACE,KAAK,CAACG,SAAS,CAAE;AACzC;AACA,IAAIP,oBAAqB;AACzB,IAAID,qBAAsB;AAC1B,IAAIE,cAAe;AACnB,IAAIR,UAAW;AACf,CAAC;;AAED;AACA;AACA;AACA,MAAMe,UAAU,gBAAGX,UAAU,CAC3B,CACE;EAAEY,SAAS,GAAG,OAAO;EAAEN,QAAQ,GAAG,KAAK;EAAEO,WAAW,GAAGA,CAAA,KAAM,CAAC,CAAC;EAAE,GAAGC;AAAK,CAAC,EAC1EC,GAAG,KACA;EACH,IAAIT,QAAQ,EAAE;IACZ,oBACEP,KAAA,CAAAiB,aAAA,CAACf,eAAe,qBACdF,KAAA,CAAAiB,aAAA,CAACP,YAAY,EAAAQ,QAAA;MAACX,QAAQ;IAAA,GAAKQ,IAAI;MAAEC,GAAG,EAAEA;IAAI,EAAE,CAC7B,CAAC;EAEtB;EAEA,oBACEhB,KAAA,CAAAiB,aAAA,CAACP,YAAY,EAAAQ,QAAA;IACXL,SAAS,EAAEA,SAAU;IACrBC,WAAW,EAAGK,CAAC,IAAK;MAClBL,WAAW,CAACK,CAAC,CAAC;MACdA,CAAC,CAACC,cAAc,CAAC,CAAC;IACpB;EAAE,GACEL,IAAI;IACRC,GAAG,EAAEA;EAAI,EACV,CAAC;AAEN,CACF,CAAC;AAEDJ,UAAU,CAACS,WAAW,GAAG,YAAY;AAErC,eAAeT,UAAU"}
|
package/dist/esm/Select/index.js
CHANGED
|
@@ -97,7 +97,7 @@ export const Placeholder = styled.span`
|
|
|
97
97
|
color: ${p => clr(p.theme.inputColorPlaceholder)};
|
|
98
98
|
${ellipsisStyles};
|
|
99
99
|
`;
|
|
100
|
-
const
|
|
100
|
+
const titleUnborderedStyles = p => p.unbordered && css`
|
|
101
101
|
font-weight: 500;
|
|
102
102
|
${!p.disabled && `color: ${clr(p.theme.colorPrimary)};`}
|
|
103
103
|
`;
|
|
@@ -106,7 +106,7 @@ const titleDisabledStyles = p => p.disabled && css`
|
|
|
106
106
|
`;
|
|
107
107
|
export const Title = styled('span', omitEmotionProps('disabled', 'unbordered'))`
|
|
108
108
|
color: ${p => clr(p.theme.colorText)};
|
|
109
|
-
${
|
|
109
|
+
${titleUnborderedStyles};
|
|
110
110
|
${titleDisabledStyles};
|
|
111
111
|
${ellipsisStyles};
|
|
112
112
|
`;
|