@semcore/button 17.0.0-prerelease.29 → 17.0.0-prerelease.31

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 (56) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/lib/cjs/component/Button/Button.js +121 -18
  3. package/lib/cjs/component/Button/Button.js.map +1 -1
  4. package/lib/cjs/component/Button/Button.type.js.map +1 -1
  5. package/lib/cjs/component/Button/SpinButton.js.map +1 -0
  6. package/lib/cjs/component/ButtonLink/ButtonLink.js +28 -54
  7. package/lib/cjs/component/ButtonLink/ButtonLink.js.map +1 -1
  8. package/lib/cjs/component/ButtonLink/ButtonLink.type.js.map +1 -1
  9. package/lib/cjs/component/ButtonLink/buttonLink.shadow.css +10 -140
  10. package/lib/cjs/index.js +3 -4
  11. package/lib/cjs/index.js.map +1 -1
  12. package/lib/es6/component/Button/Button.js +123 -20
  13. package/lib/es6/component/Button/Button.js.map +1 -1
  14. package/lib/es6/component/Button/Button.type.js.map +1 -1
  15. package/lib/es6/component/Button/SpinButton.js.map +1 -0
  16. package/lib/es6/component/ButtonLink/ButtonLink.js +29 -56
  17. package/lib/es6/component/ButtonLink/ButtonLink.js.map +1 -1
  18. package/lib/es6/component/ButtonLink/ButtonLink.type.js.map +1 -1
  19. package/lib/es6/component/ButtonLink/buttonLink.shadow.css +10 -140
  20. package/lib/es6/index.js +1 -2
  21. package/lib/es6/index.js.map +1 -1
  22. package/lib/esm/component/Button/Button.mjs +121 -17
  23. package/lib/esm/component/ButtonLink/ButtonLink.mjs +29 -54
  24. package/lib/esm/component/ButtonLink/buttonLink.shadow.css +10 -140
  25. package/lib/esm/index.mjs +1 -2
  26. package/lib/types/component/Button/Button.d.ts +28 -1
  27. package/lib/types/component/Button/Button.type.d.ts +40 -23
  28. package/lib/types/component/ButtonLink/ButtonLink.type.d.ts +14 -19
  29. package/lib/types/index.d.ts +1 -2
  30. package/package.json +7 -5
  31. package/src/component/Button/Button.tsx +148 -10
  32. package/src/component/Button/Button.type.ts +46 -34
  33. package/src/component/ButtonLink/ButtonLink.tsx +22 -26
  34. package/src/component/ButtonLink/ButtonLink.type.ts +15 -26
  35. package/src/component/ButtonLink/buttonLink.shadow.css +10 -140
  36. package/src/index.ts +1 -2
  37. package/lib/cjs/component/AbstractButton/AbstractButton.js +0 -124
  38. package/lib/cjs/component/AbstractButton/AbstractButton.js.map +0 -1
  39. package/lib/cjs/component/AbstractButton/AbstractButton.type.js +0 -2
  40. package/lib/cjs/component/AbstractButton/AbstractButton.type.js.map +0 -1
  41. package/lib/cjs/component/AbstractButton/SpinButton.js.map +0 -1
  42. package/lib/es6/component/AbstractButton/AbstractButton.js +0 -117
  43. package/lib/es6/component/AbstractButton/AbstractButton.js.map +0 -1
  44. package/lib/es6/component/AbstractButton/AbstractButton.type.js +0 -2
  45. package/lib/es6/component/AbstractButton/AbstractButton.type.js.map +0 -1
  46. package/lib/es6/component/AbstractButton/SpinButton.js.map +0 -1
  47. package/lib/esm/component/AbstractButton/AbstractButton.mjs +0 -119
  48. package/lib/types/component/AbstractButton/AbstractButton.d.ts +0 -23
  49. package/lib/types/component/AbstractButton/AbstractButton.type.d.ts +0 -36
  50. package/src/component/AbstractButton/AbstractButton.tsx +0 -161
  51. package/src/component/AbstractButton/AbstractButton.type.ts +0 -42
  52. /package/lib/cjs/component/{AbstractButton → Button}/SpinButton.js +0 -0
  53. /package/lib/es6/component/{AbstractButton → Button}/SpinButton.js +0 -0
  54. /package/lib/esm/component/{AbstractButton → Button}/SpinButton.mjs +0 -0
  55. /package/lib/types/component/{AbstractButton → Button}/SpinButton.d.ts +0 -0
  56. /package/src/component/{AbstractButton → Button}/SpinButton.tsx +0 -0
@@ -1,12 +1,26 @@
1
- import { Box } from '@semcore/base-components';
2
- import { createComponent, sstyled, Root } from '@semcore/core';
1
+ import { NeighborLocation, Box, Hint } from '@semcore/base-components';
2
+ import { Component, CORE_INSTANCE, createComponent, Root, sstyled } from '@semcore/core';
3
+ import addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';
4
+ import hasLabels from '@semcore/core/lib/utils/hasLabels';
5
+ import logger from '@semcore/core/lib/utils/logger';
6
+ import { Text } from '@semcore/typography';
3
7
  import React from 'react';
4
8
 
5
9
  import style from './button.shadow.css';
6
- import type { ButtonAddonProps, ButtonComponent, ButtonTextProps } from './Button.type';
7
- import { AbstractButton } from '../AbstractButton/AbstractButton';
10
+ import type { ButtonProps, ButtonAddonProps, ButtonTextProps, ButtonComponent } from './Button.type';
11
+ import SpinButton from './SpinButton';
8
12
 
9
- class RootButton extends AbstractButton {
13
+ export const MAP_USE_DEFAULT_THEME: Record<string, string> = {
14
+ primary: 'info',
15
+ secondary: 'muted',
16
+ tertiary: 'info',
17
+ };
18
+
19
+ type State = {
20
+ ariaLabelledByContent: null | string;
21
+ };
22
+
23
+ export class RootButton extends Component<ButtonProps, [], never, {}, State> {
10
24
  static displayName = 'Button';
11
25
  static style = style;
12
26
  static defaultProps = {
@@ -14,14 +28,138 @@ class RootButton extends AbstractButton {
14
28
  size: 'm',
15
29
  };
16
30
 
17
- protected getTextColor(): string | undefined {
18
- return undefined;
31
+ containerRef = React.createRef<HTMLButtonElement>();
32
+
33
+ state: State = {
34
+ ariaLabelledByContent: null,
35
+ };
36
+
37
+ getTextProps() {
38
+ const { size } = this.asProps;
39
+
40
+ return {
41
+ size,
42
+ 'hint:triggerRef': this.containerRef,
43
+ };
44
+ }
45
+
46
+ getAddonProps() {
47
+ const { size } = this.asProps;
48
+ return {
49
+ size,
50
+ };
51
+ }
52
+
53
+ componentDidMount() {
54
+ if (process.env.NODE_ENV !== 'production') {
55
+ logger.warn(
56
+ this.containerRef.current && !hasLabels(this.containerRef.current) && !this.asProps.title,
57
+ `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`,
58
+ this.asProps['data-ui-name'] || RootButton.displayName,
59
+ );
60
+ }
61
+
62
+ const ariaLabelledby = this.asProps['aria-labelledby'];
63
+
64
+ if (ariaLabelledby) {
65
+ setTimeout(() => {
66
+ this.setState({
67
+ ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? '',
68
+ });
69
+ }, 0);
70
+ }
71
+ }
72
+
73
+ render() {
74
+ const {
75
+ styles,
76
+ use,
77
+ theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
78
+ loading,
79
+ disabled = loading,
80
+ size,
81
+ neighborLocation,
82
+ children,
83
+ title,
84
+ ['aria-label']: ariaLabel,
85
+ Children,
86
+ addonLeft: AddonLeft,
87
+ addonRight: AddonRight,
88
+ hintPlacement,
89
+ } = this.asProps;
90
+ const SButton = Root;
91
+ // @ts-ignore
92
+ const Button = this[CORE_INSTANCE];
93
+ const useTheme = use && theme ? `${use}-${theme}` : false;
94
+ const SInner = Box;
95
+ const SSpin = Box;
96
+ const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
97
+
98
+ const showHint = (children === undefined || title);
99
+
100
+ return (
101
+ <NeighborLocation.Detect neighborLocation={neighborLocation}>
102
+ {(neighborLocation) => {
103
+ return sstyled(styles)(
104
+ <>
105
+ <SButton
106
+ render={Box}
107
+ invertOutline={theme === 'invert'}
108
+ type='button'
109
+ tag='button'
110
+ tabIndex={0}
111
+ disabled={disabled}
112
+ use:theme={useTheme}
113
+ ref={this.containerRef}
114
+ aria-busy={loading}
115
+ __excludeProps={['title']}
116
+ aria-label={showHint ? buttonAriaLabel : undefined}
117
+ neighborLocation={neighborLocation}
118
+ >
119
+ {/* @ts-ignore */}
120
+ <SInner tag='span' loading={loading} data-ui-name={`${this.asProps['data-ui-name']}.InnerWrapper`}>
121
+ {AddonLeft
122
+ ? (
123
+ <Button.Addon>
124
+ <AddonLeft />
125
+ </Button.Addon>
126
+ )
127
+ : null}
128
+ {addonTextChildren(Children, Button.Text, Button.Addon)}
129
+ {AddonRight
130
+ ? (
131
+ <Button.Addon>
132
+ <AddonRight />
133
+ </Button.Addon>
134
+ )
135
+ : null}
136
+ </SInner>
137
+ {loading && (
138
+ <SSpin tag='span'>
139
+ <SpinButton centered size={size} theme={useTheme} />
140
+ </SSpin>
141
+ )}
142
+ </SButton>
143
+ {showHint && (
144
+ <Hint
145
+ triggerRef={this.containerRef}
146
+ timeout={[250, 50]}
147
+ placement={hintPlacement}
148
+ >
149
+ {buttonAriaLabel}
150
+ </Hint>
151
+ )}
152
+ </>,
153
+ );
154
+ }}
155
+ </NeighborLocation.Detect>
156
+ );
19
157
  }
20
158
  }
21
159
 
22
- function Text(props: ButtonTextProps) {
160
+ function ButtonText(props: ButtonTextProps) {
23
161
  const SText = Root;
24
- return sstyled(props.styles)(<SText render={Box} tag='span' />);
162
+ return sstyled(props.styles)(<SText render={Text} />);
25
163
  }
26
164
 
27
165
  function Addon(props: ButtonAddonProps) {
@@ -30,7 +168,7 @@ function Addon(props: ButtonAddonProps) {
30
168
  }
31
169
 
32
170
  const Button = createComponent(RootButton, {
33
- Text,
171
+ Text: ButtonText,
34
172
  Addon,
35
173
  }) as ButtonComponent;
36
174
 
@@ -1,40 +1,52 @@
1
- import type { UnknownProperties, Intergalactic } from '@semcore/core';
2
-
3
- import type {
4
- AbstractButtonAddonProps,
5
- AbstractButtonContext,
6
- AbstractButtonTextProps,
7
- AbstractButtonProps,
8
- } from '../AbstractButton/AbstractButton.type';
9
-
10
- /**
11
- * Button size
12
- * @default m
13
- */
14
- export type ButtonSize = 'l' | 'm';
15
- /**
16
- * Button type
17
- * @default secondary
18
- */
19
- type Use = 'primary' | 'secondary' | 'tertiary';
20
-
21
- /** Button theme */
22
- type Theme = 'info' | 'success' | 'brand' | 'danger' | 'muted' | 'invert';
23
-
24
- export type ButtonProps = AbstractButtonProps<ButtonSize, Use, Theme>;
25
-
26
- export type ButtonTextProps = AbstractButtonTextProps<ButtonSize>;
27
-
28
- export type ButtonAddonProps = AbstractButtonAddonProps<ButtonSize>;
29
-
30
- export type ButtonContext = AbstractButtonContext;
1
+ import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';
2
+ import type { Intergalactic, PropGetterFn } from '@semcore/core';
3
+ import type { TextProps } from '@semcore/typography';
4
+ import type React from 'react';
5
+
6
+ export type ButtonProps = BoxProps &
7
+ NeighborItemProps & {
8
+ /** Button activity state */
9
+ active?: boolean;
10
+ /** Disabled button state */
11
+ disabled?: boolean;
12
+ /** Loading button state */
13
+ loading?: boolean;
14
+ /** Tag for the left Addon */
15
+ addonLeft?: React.ElementType;
16
+ /** Tag for the right Addon */
17
+ addonRight?: React.ElementType;
18
+ /**
19
+ * Placement for hint
20
+ * @default top
21
+ */
22
+ hintPlacement?: SimpleHintPopperProps['placement'];
23
+
24
+ /** Button size.
25
+ * @default `m`
26
+ */
27
+ size?: 'l' | 'm';
28
+ /** Button usage.
29
+ * @default `primary`
30
+ */
31
+ use?: 'primary' | 'secondary' | 'tertiary';
32
+ /** Button theme.
33
+ * @default undefined
34
+ */
35
+ theme?: 'info' | 'success' | 'brand' | 'danger' | 'muted' | 'invert';
36
+ };
37
+
38
+ export type ButtonTextProps = TextProps;
39
+
40
+ export type ButtonAddonProps = BoxProps;
41
+
42
+ export type ButtonContext = {
43
+ getTextProps: PropGetterFn;
44
+ getAddonProps: PropGetterFn;
45
+ };
31
46
 
32
47
  export type ButtonChildren = {
33
48
  Text: Intergalactic.Component<'span', ButtonTextProps>;
34
49
  Addon: Intergalactic.Component<'span', ButtonAddonProps>;
35
50
  };
36
51
 
37
- export type ButtonComponent = Intergalactic.Component<'button', ButtonProps, ButtonContext> & {
38
- Text: Intergalactic.Component<'span', ButtonTextProps>;
39
- Addon: Intergalactic.Component<'span', ButtonAddonProps>;
40
- };
52
+ export type ButtonComponent = Intergalactic.Component<'button', ButtonProps, ButtonContext> & ButtonChildren;
@@ -1,41 +1,37 @@
1
- import { Box } from '@semcore/base-components';
2
- import { createComponent, sstyled, Root } from '@semcore/core';
3
- import resolveColorEnhance from '@semcore/core/lib/utils/enhances/resolveColorEnhance';
1
+ import { createComponent, sstyled, Root, Component } from '@semcore/core';
2
+ import Link from '@semcore/link';
4
3
  import React from 'react';
5
4
 
6
5
  import style from './buttonLink.shadow.css';
7
- import type { ButtonLinkAddonProps, ButtonLinkComponent, ButtonLinkTextProps } from './ButtonLink.type';
8
- import { AbstractButton } from '../AbstractButton/AbstractButton';
6
+ import type { ButtonLinkComponent, ButtonLinkProps } from './ButtonLink.type';
9
7
 
10
- const enhance = {
11
- resolveColor: resolveColorEnhance(),
12
- };
13
-
14
- class RootButtonLink extends AbstractButton {
8
+ class RootButtonLink extends Component<ButtonLinkProps> {
15
9
  static displayName = 'ButtonLink';
16
- static enhance = Object.values(enhance);
17
10
  static style = style;
18
11
  static defaultProps = {
19
12
  use: 'primary',
13
+ size: 200,
20
14
  };
21
15
 
22
- protected getTextColor(): string | undefined {
23
- const { color, resolveColor } = this.asProps as any;
24
- return resolveColor(color);
25
- }
26
- }
27
-
28
- function Text(props: ButtonLinkTextProps) {
29
- const SText = Root;
30
- return sstyled(props.styles)(<SText render={Box} tag='span' />);
31
- }
16
+ render(): React.ReactNode {
17
+ const SButtonLink = Root;
18
+ const { disabled } = this.asProps;
32
19
 
33
- function Addon(props: ButtonLinkAddonProps) {
34
- const SAddon = Root;
35
- return sstyled(props.styles)(<SAddon render={Box} tag='span' />);
20
+ return sstyled(style)(
21
+ <SButtonLink
22
+ render={Link}
23
+ tag='button'
24
+ type='button'
25
+ use:disabled={disabled}
26
+ use:tabIndex={0}
27
+ />,
28
+ );
29
+ }
36
30
  }
37
31
 
38
32
  export const ButtonLink = createComponent(RootButtonLink, {
39
- Text,
40
- Addon,
33
+ Text: Link.Text,
34
+ Addon: Link.Addon,
35
+ }, {
36
+ parent: Link,
41
37
  }) as ButtonLinkComponent;
@@ -1,29 +1,21 @@
1
+ import type { BoxProps } from '@semcore/base-components';
1
2
  import type { Intergalactic } from '@semcore/core';
3
+ import type { LinkProps } from '@semcore/link';
4
+ import type { TextProps } from '@semcore/typography';
2
5
 
3
- import type {
4
- AbstractButtonAddonProps,
5
- AbstractButtonContext,
6
- AbstractButtonTextProps,
7
- AbstractButtonProps,
8
- } from '../AbstractButton/AbstractButton.type';
6
+ import type { ButtonContext } from '../Button/Button.type';
9
7
 
10
- /**
11
- * Button link size
12
- */
13
- export type ButtonLinkSize = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800;
14
- /**
15
- * Button link type
16
- * @default primary
17
- */
18
- type Use = 'primary' | 'secondary';
19
-
20
- export type ButtonLinkProps = AbstractButtonProps<ButtonLinkSize, Use, never>;
21
-
22
- export type ButtonLinkTextProps = AbstractButtonTextProps<ButtonLinkSize>;
8
+ export type ButtonLinkProps = Intergalactic.InternalTypings.EfficientOmit<LinkProps, 'enableVisited'> & {
9
+ /**
10
+ * Button link type
11
+ * @default primary
12
+ */
13
+ use?: 'primary' | 'secondary';
14
+ };
23
15
 
24
- export type ButtonLinkAddonProps = AbstractButtonAddonProps<ButtonLinkSize>;
16
+ export type ButtonLinkTextProps = TextProps;
25
17
 
26
- export type ButtonLinkContext = AbstractButtonContext;
18
+ export type ButtonLinkAddonProps = BoxProps;
27
19
 
28
20
  export type ButtonLinkChildren = {
29
21
  Text: Intergalactic.Component<'span', ButtonLinkTextProps>;
@@ -33,8 +25,5 @@ export type ButtonLinkChildren = {
33
25
  export type ButtonLinkComponent = Intergalactic.Component<
34
26
  'button',
35
27
  ButtonLinkProps,
36
- ButtonLinkContext
37
- > & {
38
- Text: Intergalactic.Component<'span', ButtonLinkTextProps>;
39
- Addon: Intergalactic.Component<'span', ButtonLinkAddonProps>;
40
- };
28
+ ButtonContext
29
+ > & ButtonLinkChildren;
@@ -1,59 +1,19 @@
1
- SButton {
2
- display: inline-flex;
1
+ SButtonLink {
2
+ border: none;
3
3
  font-family: inherit;
4
- font-size: var(--intergalactic-fs-200, 14px);
4
+ }
5
+
6
+ SButtonLink[use='primary']:not([color]) {
5
7
  color: var(--intergalactic-text-link, #006dca);
6
- line-height: normal;
7
- position: relative;
8
- cursor: pointer;
9
- text-decoration: none;
10
- border: none;
11
- padding: 0;
12
- margin: 0;
13
- box-shadow: none;
14
- -webkit-tap-highlight-color: transparent;
15
- background: none;
16
- transition: color 0.15s ease-in-out;
17
8
 
9
+ &[active],
18
10
  &:active,
19
11
  &:hover {
20
- text-decoration: none;
21
- }
22
-
23
- &::-moz-focus-inner {
24
- border: none;
25
- padding: 0;
26
- }
27
-
28
- &[active],
29
- &:hover,
30
- &:active {
31
12
  color: var(--intergalactic-text-link-hover-active, #044792);
32
-
33
- & SText {
34
- box-shadow: 0 1px 0 0 currentColor;
35
- }
36
- }
37
-
38
- &[enableVisited]:visited,
39
- &[enableVisited]:visited:hover {
40
- color: var(--intergalactic-text-link-visited, #8649e1);
41
13
  }
42
-
43
- SText {
44
- box-shadow: 0 1px 0 0 transparent;
45
- transition: box-shadow 0.15s ease-in-out;
46
- }
47
- }
48
-
49
- SButton[disabled] {
50
- opacity: var(--intergalactic-disabled-opacity, 0.3);
51
- cursor: default;
52
- /* Disable link interactions */
53
- pointer-events: none;
54
14
  }
55
15
 
56
- SButton[use='secondary'] {
16
+ SButtonLink[use='secondary']:not([color]) {
57
17
  color: var(--intergalactic-text-hint, #6c6e79);
58
18
 
59
19
  &[active],
@@ -61,99 +21,9 @@ SButton[use='secondary'] {
61
21
  &:hover {
62
22
  color: var(--intergalactic-text-hint-hover-active, #484a54);
63
23
  }
64
-
65
- SText {
66
- box-shadow: none;
67
- border-bottom-width: 1px;
68
- border-bottom-style: dashed;
69
- border-color: currentColor;
70
- }
71
- }
72
-
73
- SInner {
74
- display: inline-flex;
75
- align-items: baseline;
76
- justify-content: center;
77
- height: 100%;
78
- width: 100%;
79
- }
80
-
81
- SAddon {
82
- display: inline-flex;
83
- justify-content: center;
84
- align-items: baseline;
85
- vertical-align: middle;
86
- pointer-events: none;
87
- align-self: center;
88
- }
89
-
90
- SButton SAddon {
91
- &:not(:only-child):first-child {
92
- margin-right: var(--intergalactic-spacing-1x, 4px);
93
- }
94
-
95
- &:not(:only-child):last-child {
96
- margin-left: var(--intergalactic-spacing-1x, 4px);
97
- }
98
- }
99
-
100
- SButton[text-color] {
101
- color: var(--text-color);
102
-
103
- &[active],
104
- &:hover,
105
- &:active {
106
- color: var(--text-color);
107
- filter: brightness(0.8);
108
- }
109
- }
110
-
111
- SButton[size='100'] {
112
- font-size: var(--intergalactic-fs-100, 12px);
113
- line-height: var(--intergalactic-lh-100, 133%);
114
- }
115
-
116
- SButton[size='200'] {
117
- font-size: var(--intergalactic-fs-200, 14px);
118
- line-height: var(--intergalactic-lh-200, 142%);
119
- }
120
-
121
- SButton[size='300'] {
122
- font-size: var(--intergalactic-fs-300, 16px);
123
- line-height: var(--intergalactic-lh-300, 150%);
124
24
  }
125
25
 
126
- SButton[size='400'] {
127
- font-size: var(--intergalactic-fs-400, 20px);
128
- line-height: var(--intergalactic-lh-400, 120%);
129
- }
130
-
131
- SButton[size='500'] {
132
- font-size: var(--intergalactic-fs-500, 24px);
133
- line-height: var(--intergalactic-lh-500, 117%);
134
- }
135
-
136
- SButton[size='600'] {
137
- font-size: var(--intergalactic-fs-600, 32px);
138
- line-height: var(--intergalactic-lh-600, 125%);
139
- }
140
-
141
- SButton[size='700'] {
142
- font-size: var(--intergalactic-fs-700, 36px);
143
- line-height: var(--intergalactic-lh-700, 110%);
144
- }
145
-
146
- SButton[size='800'] {
147
- font-size: var(--intergalactic-fs-800, 48px);
148
- line-height: var(--intergalactic-lh-800, 117%);
149
- }
150
-
151
- @media (prefers-reduced-motion) {
152
- SButton {
153
- transition: none;
154
- }
155
-
156
- SText {
157
- transition: none;
158
- }
26
+ SButtonLink[use='secondary'] SText {
27
+ text-decoration-style: dashed;
28
+ text-decoration-color: currentColor;
159
29
  }
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { default } from './component/Button/Button';
1
+ export { default, MAP_USE_DEFAULT_THEME } from './component/Button/Button';
2
2
  export * from './component/Button/Button.type';
3
3
  export * from './component/ButtonLink/ButtonLink';
4
4
  export * from './component/ButtonLink/ButtonLink.type';
5
- export { MAP_USE_DEFAULT_THEME } from './component/AbstractButton/AbstractButton';
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.MAP_USE_DEFAULT_THEME = exports.AbstractButton = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _core = require("@semcore/core");
10
- var _baseComponents = require("@semcore/base-components");
11
- var _addonTextChildren = _interopRequireDefault(require("@semcore/core/lib/utils/addonTextChildren"));
12
- var _hasLabels = _interopRequireDefault(require("@semcore/core/lib/utils/hasLabels"));
13
- var _logger = _interopRequireDefault(require("@semcore/core/lib/utils/logger"));
14
- var _react = _interopRequireDefault(require("react"));
15
- var _SpinButton = _interopRequireDefault(require("./SpinButton"));
16
- const MAP_USE_DEFAULT_THEME = exports.MAP_USE_DEFAULT_THEME = {
17
- primary: 'info',
18
- secondary: 'muted',
19
- tertiary: 'info'
20
- };
21
- class AbstractButton extends _core.Component {
22
- constructor(...args) {
23
- super(...args);
24
- (0, _defineProperty2.default)(this, "containerRef", /*#__PURE__*/_react.default.createRef());
25
- (0, _defineProperty2.default)(this, "state", {
26
- ariaLabelledByContent: null
27
- });
28
- }
29
- getTextProps() {
30
- const {
31
- size
32
- } = this.asProps;
33
- return {
34
- size
35
- };
36
- }
37
- getAddonProps() {
38
- const {
39
- size
40
- } = this.asProps;
41
- return {
42
- size
43
- };
44
- }
45
- componentDidMount() {
46
- if (process.env.NODE_ENV !== 'production') {
47
- _logger.default.warn(this.containerRef.current && !(0, _hasLabels.default)(this.containerRef.current) && !this.asProps.title, `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`, this.asProps['data-ui-name'] || AbstractButton.displayName);
48
- _logger.default.warn(this.asProps.theme === 'warning', 'Warning theme is deprecated and will be removed in the next major release.', this.asProps['data-ui-name'] || AbstractButton.displayName);
49
- }
50
- const ariaLabelledby = this.asProps['aria-labelledby'];
51
- if (ariaLabelledby) {
52
- setTimeout(() => {
53
- this.setState({
54
- ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? ''
55
- });
56
- }, 0);
57
- }
58
- }
59
- render() {
60
- var _ref = this.asProps;
61
- const {
62
- styles,
63
- use,
64
- theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
65
- loading,
66
- disabled = loading,
67
- size,
68
- neighborLocation,
69
- children,
70
- title,
71
- ['aria-label']: ariaLabel,
72
- Children,
73
- addonLeft: AddonLeft,
74
- addonRight: AddonRight,
75
- hintPlacement
76
- } = this.asProps;
77
- const SButton = _baseComponents.Box;
78
- // @ts-ignore
79
- const Button = this[_core.CORE_INSTANCE];
80
- const useTheme = use && theme ? `${use}-${theme}` : false;
81
- const SInner = _baseComponents.Box;
82
- const SSpin = _baseComponents.Box;
83
- const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
84
- const showHint = children === undefined || title;
85
- return /*#__PURE__*/_react.default.createElement(_baseComponents.NeighborLocation.Detect, {
86
- neighborLocation: neighborLocation
87
- }, neighborLocation => {
88
- var _ref2;
89
- return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(SButton, _ref2.cn("SButton", {
90
- ...(0, _core.assignProps)({
91
- "invertOutline": theme === 'invert',
92
- "type": 'button',
93
- "tag": 'button',
94
- "tabIndex": 0,
95
- "disabled": disabled,
96
- "use:theme": useTheme,
97
- "ref": this.containerRef,
98
- "text-color": this.getTextColor(),
99
- "aria-busy": loading,
100
- "__excludeProps": ['title'],
101
- "aria-label": showHint ? buttonAriaLabel : undefined,
102
- "neighborLocation": neighborLocation
103
- }, _ref)
104
- }), /*#__PURE__*/_react.default.createElement(SInner, _ref2.cn("SInner", {
105
- "tag": 'span',
106
- "loading": loading,
107
- "data-ui-name": `${this.asProps['data-ui-name']}.InnerWrapper`
108
- }), AddonLeft ? /*#__PURE__*/_react.default.createElement(Button.Addon, null, /*#__PURE__*/_react.default.createElement(AddonLeft, _ref2.cn("AddonLeft", {}))) : null, (0, _addonTextChildren.default)(Children, Button.Text, Button.Addon), AddonRight ? /*#__PURE__*/_react.default.createElement(Button.Addon, null, /*#__PURE__*/_react.default.createElement(AddonRight, _ref2.cn("AddonRight", {}))) : null), loading && /*#__PURE__*/_react.default.createElement(SSpin, _ref2.cn("SSpin", {
109
- "tag": 'span'
110
- }), /*#__PURE__*/_react.default.createElement(_SpinButton.default, _ref2.cn("SpinButton", {
111
- "centered": true,
112
- "size": size,
113
- "theme": useTheme
114
- })))), showHint && /*#__PURE__*/_react.default.createElement(_baseComponents.Hint, _ref2.cn("Hint", {
115
- "triggerRef": this.containerRef,
116
- "timeout": [250, 50],
117
- "placement": hintPlacement
118
- }), buttonAriaLabel));
119
- });
120
- }
121
- }
122
- exports.AbstractButton = AbstractButton;
123
- (0, _defineProperty2.default)(AbstractButton, "displayName", 'AbstractButton');
124
- //# sourceMappingURL=AbstractButton.js.map