@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.
Files changed (49) hide show
  1. package/dist/cjs/Button/ButtonContent.js +1 -1
  2. package/dist/cjs/Button/ButtonContent.js.map +1 -1
  3. package/dist/cjs/Button/index.js +2 -2
  4. package/dist/cjs/Button/index.js.map +1 -1
  5. package/dist/cjs/Button/utils/useButtonColors.js +1 -1
  6. package/dist/cjs/Button/utils/useButtonColors.js.map +1 -1
  7. package/dist/cjs/ButtonLink/index.js +94 -0
  8. package/dist/cjs/ButtonLink/index.js.map +1 -0
  9. package/dist/cjs/Link/index.js +20 -18
  10. package/dist/cjs/Link/index.js.map +1 -1
  11. package/dist/cjs/LinkButton/index.js +22 -50
  12. package/dist/cjs/LinkButton/index.js.map +1 -1
  13. package/dist/cjs/Select/index.js +2 -2
  14. package/dist/cjs/Select/index.js.map +1 -1
  15. package/dist/cjs/index.js +19 -0
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/esm/Button/ButtonContent.js +1 -1
  18. package/dist/esm/Button/ButtonContent.js.map +1 -1
  19. package/dist/esm/Button/index.js +2 -2
  20. package/dist/esm/Button/index.js.map +1 -1
  21. package/dist/esm/Button/utils/useButtonColors.js +1 -1
  22. package/dist/esm/Button/utils/useButtonColors.js.map +1 -1
  23. package/dist/esm/ButtonLink/index.js +78 -0
  24. package/dist/esm/ButtonLink/index.js.map +1 -0
  25. package/dist/esm/Link/index.js +36 -23
  26. package/dist/esm/Link/index.js.map +1 -1
  27. package/dist/esm/LinkButton/index.js +29 -47
  28. package/dist/esm/LinkButton/index.js.map +1 -1
  29. package/dist/esm/Select/index.js +2 -2
  30. package/dist/esm/Select/index.js.map +1 -1
  31. package/dist/esm/index.js +2 -0
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/types/ButtonLink/index.d.ts +286 -0
  34. package/dist/types/ButtonLink/index.d.ts.map +1 -0
  35. package/dist/types/Link/index.d.ts +7 -0
  36. package/dist/types/Link/index.d.ts.map +1 -1
  37. package/dist/types/LinkButton/index.d.ts +7 -283
  38. package/dist/types/LinkButton/index.d.ts.map +1 -1
  39. package/dist/types/index.d.ts +2 -0
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/package.json +5 -5
  42. package/src/Button/ButtonContent.tsx +1 -1
  43. package/src/Button/index.tsx +2 -2
  44. package/src/Button/utils/useButtonColors.ts +1 -1
  45. package/src/ButtonLink/index.tsx +102 -0
  46. package/src/Link/index.tsx +57 -24
  47. package/src/LinkButton/index.tsx +50 -62
  48. package/src/Select/index.tsx +2 -2
  49. package/src/index.ts +2 -0
@@ -22,6 +22,11 @@ export interface LinkProps extends JsxAProps, ReactRouterLinkProps, WithSize {
22
22
  * @default hover
23
23
  */
24
24
  underline?: 'hover' | 'always' | 'never';
25
+ /**
26
+ * Whether the link is disabled.
27
+ * @default false
28
+ */
29
+ disabled?: boolean;
25
30
  /**
26
31
  * The custom link component.
27
32
  * For example, the Link from react-router-dom.
@@ -30,9 +35,6 @@ export interface LinkProps extends JsxAProps, ReactRouterLinkProps, WithSize {
30
35
  as?: React.ElementType;
31
36
  }
32
37
 
33
- /**
34
- * Sets base underline styles.
35
- */
36
38
  const underlineBaseStyles = (p) => css`
37
39
  position: relative;
38
40
  display: inline-block;
@@ -48,10 +50,7 @@ const underlineBaseStyles = (p) => css`
48
50
  }
49
51
  `;
50
52
 
51
- /**
52
- * Sets underline styles on hover.
53
- */
54
- const underlineHoverStyles = (p) =>
53
+ export const underlineHoverStyles = (p) =>
55
54
  p.underline === 'hover' &&
56
55
  css`
57
56
  @media (hover: hover) {
@@ -71,10 +70,7 @@ const underlineHoverStyles = (p) =>
71
70
  }
72
71
  `;
73
72
 
74
- /**
75
- * Sets underline styles always.
76
- */
77
- const underlineAlwaysStyles = (p) =>
73
+ export const underlineAlwaysStyles = (p) =>
78
74
  p.underline === 'always' &&
79
75
  css`
80
76
  ${underlineBaseStyles(p)};
@@ -85,9 +81,26 @@ const underlineAlwaysStyles = (p) =>
85
81
  }
86
82
  `;
87
83
 
84
+ const disabledStyles = (p) =>
85
+ p.disabled &&
86
+ css`
87
+ pointer-events: none;
88
+
89
+ &,
90
+ &:active,
91
+ &:focus {
92
+ color: ${clr(p.theme.inputColorPlaceholder)};
93
+ }
94
+ `;
95
+
96
+ export const DisabledWrapper = styled.div`
97
+ display: inline-block;
98
+ cursor: not-allowed;
99
+ `;
100
+
88
101
  const StyledLink = styled(
89
102
  'a',
90
- omitEmotionProps('size', 'underline', 'as')
103
+ omitEmotionProps('size', 'underline', 'disabled', 'as')
91
104
  )<LinkProps>`
92
105
  ${resetFocusStyles};
93
106
 
@@ -103,6 +116,7 @@ const StyledLink = styled(
103
116
 
104
117
  ${underlineHoverStyles};
105
118
  ${underlineAlwaysStyles};
119
+ ${disabledStyles};
106
120
  ${sizeStyles};
107
121
  `;
108
122
 
@@ -110,18 +124,37 @@ const StyledLink = styled(
110
124
  * The link component to navigate between pages.
111
125
  */
112
126
  const Link = forwardRef<HTMLAnchorElement, LinkProps>(
113
- ({ underline = 'hover', as, onMouseDown = () => {}, ...rest }, ref) => (
114
- <StyledLink
115
- underline={underline}
116
- as={as}
117
- onMouseDown={(e) => {
118
- onMouseDown(e);
119
- e.preventDefault();
120
- }}
121
- {...rest}
122
- ref={ref}
123
- />
124
- )
127
+ (
128
+ {
129
+ underline = 'hover',
130
+ disabled = false,
131
+ as,
132
+ onMouseDown = () => {},
133
+ ...rest
134
+ },
135
+ ref
136
+ ) => {
137
+ if (disabled) {
138
+ return (
139
+ <DisabledWrapper>
140
+ <StyledLink disabled {...rest} ref={ref} />
141
+ </DisabledWrapper>
142
+ );
143
+ }
144
+
145
+ return (
146
+ <StyledLink
147
+ underline={underline}
148
+ as={as}
149
+ onMouseDown={(e) => {
150
+ onMouseDown(e);
151
+ e.preventDefault();
152
+ }}
153
+ {...rest}
154
+ ref={ref}
155
+ />
156
+ );
157
+ }
125
158
  );
126
159
 
127
160
  Link.displayName = 'Link';
@@ -1,92 +1,80 @@
1
1
  import { css } from '@emotion/react';
2
2
  import styled from '@emotion/styled';
3
+ import { resetButtonStyles, sizeStyles, WithSize } from '@os-design/styles';
4
+ import { clr } from '@os-design/theming';
3
5
  import { omitEmotionProps } from '@os-design/utils';
4
6
  import React, { forwardRef } from 'react';
5
- import { ButtonProps, StyledButton } from '../Button';
6
- import ButtonContent from '../Button/ButtonContent';
7
- import useButtonColors from '../Button/utils/useButtonColors';
8
- import { LinkProps, ReactRouterLinkProps } from '../Link';
7
+ import {
8
+ DisabledWrapper,
9
+ underlineAlwaysStyles,
10
+ underlineHoverStyles,
11
+ } from '../Link';
9
12
 
10
- type JsxAProps = Omit<JSX.IntrinsicElements['a'], 'type' | 'ref'>;
11
- export type LinkButtonProps = JsxAProps &
12
- ReactRouterLinkProps &
13
- Pick<LinkProps, 'as'> &
14
- ButtonProps;
13
+ type JsxButtonProps = Omit<JSX.IntrinsicElements['button'], 'ref'>;
14
+
15
+ export interface LinkButtonProps extends JsxButtonProps, WithSize {
16
+ /**
17
+ * Type of the underline styles.
18
+ * @default hover
19
+ */
20
+ underline?: 'hover' | 'always' | 'never';
21
+ /**
22
+ * Whether the link is disabled.
23
+ * @default false
24
+ */
25
+ disabled?: boolean;
26
+ }
15
27
 
16
28
  const disabledStyles = (p) =>
17
29
  p.disabled &&
18
30
  css`
19
- pointer-events: none;
31
+ cursor: inherit;
32
+ color: ${clr(p.theme.inputColorPlaceholder)};
20
33
  `;
21
34
 
22
- const StyledLinkButton = styled(
23
- StyledButton.withComponent('a'),
24
- omitEmotionProps('as', 'disabled')
25
- )`
26
- text-decoration: none;
27
- display: inline-flex;
35
+ const StyledButton = styled(
36
+ 'button',
37
+ omitEmotionProps('size', 'underline')
38
+ )<LinkButtonProps>`
39
+ ${resetButtonStyles};
40
+
41
+ cursor: pointer;
42
+ text-align: left;
43
+ line-height: 1.2;
44
+ color: ${(p) => clr(p.theme.linkColor)};
45
+
46
+ ${underlineHoverStyles};
47
+ ${underlineAlwaysStyles};
28
48
  ${disabledStyles};
49
+ ${sizeStyles};
29
50
  `;
30
51
 
31
52
  /**
32
- * The button that is rendered as the a tag.
53
+ * The link component that is rendered as a button.
33
54
  */
34
- const LinkButton = forwardRef<HTMLAnchorElement, LinkButtonProps>(
55
+ const LinkButton = forwardRef<HTMLButtonElement, LinkButtonProps>(
35
56
  (
36
- {
37
- type = 'primary',
38
- danger = false,
39
- left,
40
- right,
41
- wide = 'default',
42
- loading = false,
43
- disabled = false,
44
- size,
45
- as,
46
- onMouseDown = () => {},
47
- onKeyDown = () => {},
48
- children,
49
- ...rest
50
- },
57
+ { underline = 'hover', disabled = false, onMouseDown = () => {}, ...rest },
51
58
  ref
52
59
  ) => {
53
- const { buttonColors, loadingColors } = useButtonColors({
54
- type,
55
- danger,
56
- disabled,
57
- });
60
+ if (disabled) {
61
+ return (
62
+ <DisabledWrapper>
63
+ <StyledButton disabled {...rest} ref={ref} />
64
+ </DisabledWrapper>
65
+ );
66
+ }
58
67
 
59
68
  return (
60
- <StyledLinkButton
61
- btnType={type}
62
- colors={buttonColors}
63
- wide={wide}
64
- loading={loading}
65
- disabled={disabled || loading}
66
- size={size}
67
- as={as}
69
+ <StyledButton
70
+ underline={underline}
68
71
  onMouseDown={(e) => {
69
72
  onMouseDown(e);
70
73
  e.preventDefault();
71
74
  }}
72
- onKeyDown={(e) => {
73
- onKeyDown(e);
74
- if (disabled || loading) e.preventDefault();
75
- }}
76
- aria-disabled={disabled || loading}
77
- aria-busy={loading}
78
75
  {...rest}
79
76
  ref={ref}
80
- >
81
- <ButtonContent
82
- left={left}
83
- right={right}
84
- loading={loading}
85
- loadingColors={loadingColors}
86
- >
87
- {children}
88
- </ButtonContent>
89
- </StyledLinkButton>
77
+ />
90
78
  );
91
79
  }
92
80
  );
@@ -331,7 +331,7 @@ export const Placeholder = styled.span`
331
331
  ${ellipsisStyles};
332
332
  `;
333
333
 
334
- const titleUnborderedTitleStyles = (p) =>
334
+ const titleUnborderedStyles = (p) =>
335
335
  p.unbordered &&
336
336
  css`
337
337
  font-weight: 500;
@@ -350,7 +350,7 @@ export const Title = styled(
350
350
  omitEmotionProps('disabled', 'unbordered')
351
351
  )<TitleProps>`
352
352
  color: ${(p) => clr(p.theme.colorText)};
353
- ${titleUnborderedTitleStyles};
353
+ ${titleUnborderedStyles};
354
354
  ${titleDisabledStyles};
355
355
  ${ellipsisStyles};
356
356
  `;
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export { default as AvatarSkeleton } from './AvatarSkeleton';
4
4
  export { default as Breadcrumb } from './Breadcrumb';
5
5
  export { default as BreadcrumbItem } from './BreadcrumbItem';
6
6
  export { default as Button } from './Button';
7
+ export { default as ButtonLink } from './ButtonLink';
7
8
  export { default as Checkbox } from './Checkbox';
8
9
  export { default as CheckboxSkeleton } from './CheckboxSkeleton';
9
10
  export { default as DatePicker } from './DatePicker';
@@ -68,6 +69,7 @@ export * from './AvatarSkeleton';
68
69
  export * from './Breadcrumb';
69
70
  export * from './BreadcrumbItem';
70
71
  export * from './Button';
72
+ export * from './ButtonLink';
71
73
  export * from './Checkbox';
72
74
  export * from './CheckboxSkeleton';
73
75
  export * from './DatePicker';