@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 +0,0 @@
1
- {"version":3,"file":"AbstractButton.js","names":["_core","require","_baseComponents","_addonTextChildren","_interopRequireDefault","_hasLabels","_logger","_react","_SpinButton","MAP_USE_DEFAULT_THEME","exports","primary","secondary","tertiary","AbstractButton","Component","constructor","args","_defineProperty2","default","React","createRef","ariaLabelledByContent","getTextProps","size","asProps","getAddonProps","componentDidMount","process","env","NODE_ENV","logger","warn","containerRef","current","hasLabels","title","displayName","theme","ariaLabelledby","setTimeout","setState","document","getElementById","textContent","render","_ref","styles","use","loading","disabled","neighborLocation","children","ariaLabel","Children","addonLeft","AddonLeft","addonRight","AddonRight","hintPlacement","SButton","Box","Button","CORE_INSTANCE","useTheme","SInner","SSpin","buttonAriaLabel","state","showHint","undefined","createElement","NeighborLocation","Detect","_ref2","sstyled","Fragment","cn","assignProps","getTextColor","Addon","addonTextChildren","Text","Hint"],"sources":["../../../../src/component/AbstractButton/AbstractButton.tsx"],"sourcesContent":["import { NeighborLocation, Box, Hint } from '@semcore/base-components';\nimport { Component, CORE_INSTANCE, Root, sstyled } from '@semcore/core';\nimport addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';\nimport hasLabels from '@semcore/core/lib/utils/hasLabels';\nimport logger from '@semcore/core/lib/utils/logger';\nimport React from 'react';\n\nimport type { AbstractButtonProps } from './AbstractButton.type';\nimport SpinButton from './SpinButton';\n\nexport const MAP_USE_DEFAULT_THEME: Record<string, string> = {\n primary: 'info',\n secondary: 'muted',\n tertiary: 'info',\n};\n\ntype Props = AbstractButtonProps<any, any, any>;\n\ntype State = {\n ariaLabelledByContent: null | string;\n};\n\nexport abstract class AbstractButton extends Component<Props, [], never, {}, State> {\n static displayName = 'AbstractButton';\n\n containerRef = React.createRef<HTMLButtonElement>();\n\n state: State = {\n ariaLabelledByContent: null,\n };\n\n protected abstract getTextColor(): string | undefined;\n\n getTextProps() {\n const { size } = this.asProps;\n\n return {\n size,\n };\n }\n\n getAddonProps() {\n const { size } = this.asProps;\n return {\n size,\n };\n }\n\n componentDidMount() {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(\n this.containerRef.current && !hasLabels(this.containerRef.current) && !this.asProps.title,\n `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`,\n this.asProps['data-ui-name'] || AbstractButton.displayName,\n );\n\n logger.warn(\n this.asProps.theme === 'warning',\n 'Warning theme is deprecated and will be removed in the next major release.',\n this.asProps['data-ui-name'] || AbstractButton.displayName,\n );\n }\n\n const ariaLabelledby = this.asProps['aria-labelledby'];\n\n if (ariaLabelledby) {\n setTimeout(() => {\n this.setState({\n ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? '',\n });\n }, 0);\n }\n }\n\n render() {\n const {\n styles,\n use,\n theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],\n loading,\n disabled = loading,\n size,\n neighborLocation,\n children,\n title,\n ['aria-label']: ariaLabel,\n Children,\n addonLeft: AddonLeft,\n addonRight: AddonRight,\n hintPlacement,\n } = this.asProps;\n const SButton = Root;\n // @ts-ignore\n const Button = this[CORE_INSTANCE];\n const useTheme = use && theme ? `${use}-${theme}` : false;\n const SInner = Box;\n const SSpin = Box;\n const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';\n\n const showHint = (children === undefined || title);\n\n return (\n <NeighborLocation.Detect neighborLocation={neighborLocation}>\n {(neighborLocation) => {\n return sstyled(styles)(\n <>\n <SButton\n render={Box}\n invertOutline={theme === 'invert'}\n type='button'\n tag='button'\n tabIndex={0}\n disabled={disabled}\n use:theme={useTheme}\n ref={this.containerRef}\n text-color={this.getTextColor()}\n aria-busy={loading}\n __excludeProps={['title']}\n aria-label={showHint ? buttonAriaLabel : undefined}\n neighborLocation={neighborLocation}\n >\n {/* @ts-ignore */}\n <SInner tag='span' loading={loading} data-ui-name={`${this.asProps['data-ui-name']}.InnerWrapper`}>\n {AddonLeft\n ? (\n <Button.Addon>\n <AddonLeft />\n </Button.Addon>\n )\n : null}\n {addonTextChildren(Children, Button.Text, Button.Addon)}\n {AddonRight\n ? (\n <Button.Addon>\n <AddonRight />\n </Button.Addon>\n )\n : null}\n </SInner>\n {loading && (\n <SSpin tag='span'>\n <SpinButton centered size={size} theme={useTheme} />\n </SSpin>\n )}\n </SButton>\n {showHint && (\n <Hint\n triggerRef={this.containerRef}\n timeout={[250, 50]}\n placement={hintPlacement}\n >\n {buttonAriaLabel}\n </Hint>\n )}\n </>,\n );\n }}\n </NeighborLocation.Detect>\n );\n }\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AADA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,OAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,MAAA,GAAAH,sBAAA,CAAAH,OAAA;AAGA,IAAAO,WAAA,GAAAJ,sBAAA,CAAAH,OAAA;AAEO,MAAMQ,qBAA6C,GAAAC,OAAA,CAAAD,qBAAA,GAAG;EAC3DE,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,OAAO;EAClBC,QAAQ,EAAE;AACZ,CAAC;AAQM,MAAeC,cAAc,SAASC,eAAS,CAA8B;EAAAC,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,qCAGnEC,cAAK,CAACC,SAAS,CAAoB,CAAC;IAAA,IAAAH,gBAAA,CAAAC,OAAA,iBAEpC;MACbG,qBAAqB,EAAE;IACzB,CAAC;EAAA;EAIDC,YAAYA,CAAA,EAAG;IACb,MAAM;MAAEC;IAAK,CAAC,GAAG,IAAI,CAACC,OAAO;IAE7B,OAAO;MACLD;IACF,CAAC;EACH;EAEAE,aAAaA,CAAA,EAAG;IACd,MAAM;MAAEF;IAAK,CAAC,GAAG,IAAI,CAACC,OAAO;IAC7B,OAAO;MACLD;IACF,CAAC;EACH;EAEAG,iBAAiBA,CAAA,EAAG;IAClB,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;MACzCC,eAAM,CAACC,IAAI,CACT,IAAI,CAACC,YAAY,CAACC,OAAO,IAAI,CAAC,IAAAC,kB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,CAAAoD,aAAA,CAACT,MAAM,CAACkB,KAAK,qBACXzE,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAACf,SAAS,EAAAkB,KAAA,CAAAG,EAAA,iBAAE,CACA,CAAC,GAEjB,IAAI,EACP,IAAAI,0BAAiB,EAAC3B,QAAQ,EAAEQ,MAAM,CAACoB,IAAI,EAAEpB,MAAM,CAACkB,KAAK,CAAC,EACtDtB,UAAU,gBAELnD,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAACT,MAAM,CAACkB,KAAK,qBACXzE,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAACb,UAAU,EAAAgB,KAAA,CAAAG,EAAA,kBAAE,CACD,CAAC,GAEjB,IACE,CAAC,EACR5B,OAAO,iBACN1C,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAACL,KAAK,EAAAQ,KAAA,CAAAG,EAAA;QAAA,OAAK;MAAM,iBACftE,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAAC/D,WAAA,CAAAW,OAAU,EAAAuD,KAAA,CAAAG,EAAA;QAAA;QAAA,QAAgBrD,IAAI;QAAA,SAASwC;MAAQ,EAAG,CAC9C,CAEF,CAAC,EACTK,QAAQ,iBACP9D,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAACrE,eAAA,CAAAiF,IAAI,EAAAT,KAAA,CAAAG,EAAA;QAAA,cACS,IAAI,CAAC5C,YAAY;QAAA,WACpB,CAAC,GAAG,EAAE,EAAE,CAAC;QAAA,aACP0B;MAAa,IAEvBQ,eACG,CAER,CAAC;IAEP,CACuB,CAAC;EAE9B;AACF;AAACzD,OAAA,CAAAI,cAAA,GAAAA,cAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EA1IqBL,cAAc,iBACb,gBAAgB","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=AbstractButton.type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractButton.type.js","names":[],"sources":["../../../../src/component/AbstractButton/AbstractButton.type.ts"],"sourcesContent":["import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';\nimport type { PropGetterFn } from '@semcore/core';\nimport type React from 'react';\n\nexport type AbstractButtonProps<S, U, T> = BoxProps &\n NeighborItemProps & {\n /** Button activity state */\n active?: boolean;\n /** Disabled button state */\n disabled?: boolean;\n /** Loading button state */\n loading?: boolean;\n /** Tag for the left Addon */\n addonLeft?: React.ElementType;\n /** Tag for the right Addon */\n addonRight?: React.ElementType;\n /**\n * Placement for hint\n * @default top\n */\n hintPlacement?: SimpleHintPopperProps['placement'];\n\n /** Button size. Defined in Button.type or ButtonLink.type */\n size?: S;\n /** Button usage. Defined in Button.type or ButtonLink.type */\n use?: U;\n /** Button theme. Defined in Button.type or ButtonLink.type */\n theme?: T;\n };\n\nexport type AbstractButtonAddonProps<S> = BoxProps & {\n size?: S;\n};\n\nexport type AbstractButtonTextProps<S> = BoxProps & {\n size?: S;\n};\n\nexport type AbstractButtonContext = {\n getTextProps: PropGetterFn;\n getAddonProps: PropGetterFn;\n};\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpinButton.js","names":["_spin","_interopRequireDefault","require","_react","SPIN_SIZE_MAP","exports","xl","l","m","s","SpinButton","theme","size","others","default","createElement","_extends2"],"sources":["../../../../src/component/AbstractButton/SpinButton.tsx"],"sourcesContent":["import Spin from '@semcore/spin';\nimport React from 'react';\n\nexport const SPIN_SIZE_MAP: Record<string, string> = {\n xl: 'm',\n l: 's',\n m: 'xs',\n s: 'xxs',\n};\n\nexport default function SpinButton({ theme, size, ...others }: any) {\n return (\n <Spin\n size={typeof size === 'string' ? SPIN_SIZE_MAP[size] : size}\n theme='currentColor'\n {...others}\n />\n );\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,aAAqC,GAAAC,OAAA,CAAAD,aAAA,GAAG;EACnDE,EAAE,EAAE,GAAG;EACPC,CAAC,EAAE,GAAG;EACNC,CAAC,EAAE,IAAI;EACPC,CAAC,EAAE;AACL,CAAC;AAEc,SAASC,UAAUA,CAAC;EAAEC,KAAK;EAAEC,IAAI;EAAE,GAAGC;AAAY,CAAC,EAAE;EAClE,oBACEV,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACf,KAAA,CAAAc,OAAI,MAAAE,SAAA,CAAAF,OAAA;IACHF,IAAI,EAAE,OAAOA,IAAI,KAAK,QAAQ,GAAGR,aAAa,CAACQ,IAAI,CAAC,GAAGA,IAAK;IAC5DD,KAAK,EAAC;EAAc,GAChBE,MAAM,CACX,CAAC;AAEN","ignoreList":[]}
@@ -1,117 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { assignProps as _assignProps } from "@semcore/core";
3
- import { NeighborLocation, Box, Hint } from '@semcore/base-components';
4
- import { Component, CORE_INSTANCE, Root, sstyled } from '@semcore/core';
5
- import addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';
6
- import hasLabels from '@semcore/core/lib/utils/hasLabels';
7
- import logger from '@semcore/core/lib/utils/logger';
8
- import React from 'react';
9
- import SpinButton from './SpinButton';
10
- export const MAP_USE_DEFAULT_THEME = {
11
- primary: 'info',
12
- secondary: 'muted',
13
- tertiary: 'info'
14
- };
15
- export class AbstractButton extends Component {
16
- constructor(...args) {
17
- super(...args);
18
- _defineProperty(this, "containerRef", /*#__PURE__*/React.createRef());
19
- _defineProperty(this, "state", {
20
- ariaLabelledByContent: null
21
- });
22
- }
23
- getTextProps() {
24
- const {
25
- size
26
- } = this.asProps;
27
- return {
28
- size
29
- };
30
- }
31
- getAddonProps() {
32
- const {
33
- size
34
- } = this.asProps;
35
- return {
36
- size
37
- };
38
- }
39
- componentDidMount() {
40
- if (process.env.NODE_ENV !== 'production') {
41
- logger.warn(this.containerRef.current && !hasLabels(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);
42
- logger.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);
43
- }
44
- const ariaLabelledby = this.asProps['aria-labelledby'];
45
- if (ariaLabelledby) {
46
- setTimeout(() => {
47
- this.setState({
48
- ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? ''
49
- });
50
- }, 0);
51
- }
52
- }
53
- render() {
54
- var _ref = this.asProps;
55
- const {
56
- styles,
57
- use,
58
- theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
59
- loading,
60
- disabled = loading,
61
- size,
62
- neighborLocation,
63
- children,
64
- title,
65
- ['aria-label']: ariaLabel,
66
- Children,
67
- addonLeft: AddonLeft,
68
- addonRight: AddonRight,
69
- hintPlacement
70
- } = this.asProps;
71
- const SButton = Box;
72
- // @ts-ignore
73
- const Button = this[CORE_INSTANCE];
74
- const useTheme = use && theme ? `${use}-${theme}` : false;
75
- const SInner = Box;
76
- const SSpin = Box;
77
- const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
78
- const showHint = children === undefined || title;
79
- return /*#__PURE__*/React.createElement(NeighborLocation.Detect, {
80
- neighborLocation: neighborLocation
81
- }, neighborLocation => {
82
- var _ref2;
83
- return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SButton, _ref2.cn("SButton", {
84
- ..._assignProps({
85
- "invertOutline": theme === 'invert',
86
- "type": 'button',
87
- "tag": 'button',
88
- "tabIndex": 0,
89
- "disabled": disabled,
90
- "use:theme": useTheme,
91
- "ref": this.containerRef,
92
- "text-color": this.getTextColor(),
93
- "aria-busy": loading,
94
- "__excludeProps": ['title'],
95
- "aria-label": showHint ? buttonAriaLabel : undefined,
96
- "neighborLocation": neighborLocation
97
- }, _ref)
98
- }), /*#__PURE__*/React.createElement(SInner, _ref2.cn("SInner", {
99
- "tag": 'span',
100
- "loading": loading,
101
- "data-ui-name": `${this.asProps['data-ui-name']}.InnerWrapper`
102
- }), AddonLeft ? /*#__PURE__*/React.createElement(Button.Addon, null, /*#__PURE__*/React.createElement(AddonLeft, _ref2.cn("AddonLeft", {}))) : null, addonTextChildren(Children, Button.Text, Button.Addon), AddonRight ? /*#__PURE__*/React.createElement(Button.Addon, null, /*#__PURE__*/React.createElement(AddonRight, _ref2.cn("AddonRight", {}))) : null), loading && /*#__PURE__*/React.createElement(SSpin, _ref2.cn("SSpin", {
103
- "tag": 'span'
104
- }), /*#__PURE__*/React.createElement(SpinButton, _ref2.cn("SpinButton", {
105
- "centered": true,
106
- "size": size,
107
- "theme": useTheme
108
- })))), showHint && /*#__PURE__*/React.createElement(Hint, _ref2.cn("Hint", {
109
- "triggerRef": this.containerRef,
110
- "timeout": [250, 50],
111
- "placement": hintPlacement
112
- }), buttonAriaLabel));
113
- });
114
- }
115
- }
116
- _defineProperty(AbstractButton, "displayName", 'AbstractButton');
117
- //# sourceMappingURL=AbstractButton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractButton.js","names":["NeighborLocation","Box","Hint","Component","CORE_INSTANCE","Root","sstyled","addonTextChildren","hasLabels","logger","React","SpinButton","MAP_USE_DEFAULT_THEME","primary","secondary","tertiary","AbstractButton","constructor","args","_defineProperty","createRef","ariaLabelledByContent","getTextProps","size","asProps","getAddonProps","componentDidMount","process","env","NODE_ENV","warn","containerRef","current","title","displayName","theme","ariaLabelledby","setTimeout","setState","document","getElementById","textContent","render","_ref","styles","use","loading","disabled","neighborLocation","children","ariaLabel","Children","addonLeft","AddonLeft","addonRight","AddonRight","hintPlacement","SButton","Button","useTheme","SInner","SSpin","buttonAriaLabel","state","showHint","undefined","createElement","Detect","_ref2","Fragment","cn","_assignProps","getTextColor","Addon","Text"],"sources":["../../../../src/component/AbstractButton/AbstractButton.tsx"],"sourcesContent":["import { NeighborLocation, Box, Hint } from '@semcore/base-components';\nimport { Component, CORE_INSTANCE, Root, sstyled } from '@semcore/core';\nimport addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';\nimport hasLabels from '@semcore/core/lib/utils/hasLabels';\nimport logger from '@semcore/core/lib/utils/logger';\nimport React from 'react';\n\nimport type { AbstractButtonProps } from './AbstractButton.type';\nimport SpinButton from './SpinButton';\n\nexport const MAP_USE_DEFAULT_THEME: Record<string, string> = {\n primary: 'info',\n secondary: 'muted',\n tertiary: 'info',\n};\n\ntype Props = AbstractButtonProps<any, any, any>;\n\ntype State = {\n ariaLabelledByContent: null | string;\n};\n\nexport abstract class AbstractButton extends Component<Props, [], never, {}, State> {\n static displayName = 'AbstractButton';\n\n containerRef = React.createRef<HTMLButtonElement>();\n\n state: State = {\n ariaLabelledByContent: null,\n };\n\n protected abstract getTextColor(): string | undefined;\n\n getTextProps() {\n const { size } = this.asProps;\n\n return {\n size,\n };\n }\n\n getAddonProps() {\n const { size } = this.asProps;\n return {\n size,\n };\n }\n\n componentDidMount() {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(\n this.containerRef.current && !hasLabels(this.containerRef.current) && !this.asProps.title,\n `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`,\n this.asProps['data-ui-name'] || AbstractButton.displayName,\n );\n\n logger.warn(\n this.asProps.theme === 'warning',\n 'Warning theme is deprecated and will be removed in the next major release.',\n this.asProps['data-ui-name'] || AbstractButton.displayName,\n );\n }\n\n const ariaLabelledby = this.asProps['aria-labelledby'];\n\n if (ariaLabelledby) {\n setTimeout(() => {\n this.setState({\n ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? '',\n });\n }, 0);\n }\n }\n\n render() {\n const {\n styles,\n use,\n theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],\n loading,\n disabled = loading,\n size,\n neighborLocation,\n children,\n title,\n ['aria-label']: ariaLabel,\n Children,\n addonLeft: AddonLeft,\n addonRight: AddonRight,\n hintPlacement,\n } = this.asProps;\n const SButton = Root;\n // @ts-ignore\n const Button = this[CORE_INSTANCE];\n const useTheme = use && theme ? `${use}-${theme}` : false;\n const SInner = Box;\n const SSpin = Box;\n const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';\n\n const showHint = (children === undefined || title);\n\n return (\n <NeighborLocation.Detect neighborLocation={neighborLocation}>\n {(neighborLocation) => {\n return sstyled(styles)(\n <>\n <SButton\n render={Box}\n invertOutline={theme === 'invert'}\n type='button'\n tag='button'\n tabIndex={0}\n disabled={disabled}\n use:theme={useTheme}\n ref={this.containerRef}\n text-color={this.getTextColor()}\n aria-busy={loading}\n __excludeProps={['title']}\n aria-label={showHint ? buttonAriaLabel : undefined}\n neighborLocation={neighborLocation}\n >\n {/* @ts-ignore */}\n <SInner tag='span' loading={loading} data-ui-name={`${this.asProps['data-ui-name']}.InnerWrapper`}>\n {AddonLeft\n ? (\n <Button.Addon>\n <AddonLeft />\n </Button.Addon>\n )\n : null}\n {addonTextChildren(Children, Button.Text, Button.Addon)}\n {AddonRight\n ? (\n <Button.Addon>\n <AddonRight />\n </Button.Addon>\n )\n : null}\n </SInner>\n {loading && (\n <SSpin tag='span'>\n <SpinButton centered size={size} theme={useTheme} />\n </SSpin>\n )}\n </SButton>\n {showHint && (\n <Hint\n triggerRef={this.containerRef}\n timeout={[250, 50]}\n placement={hintPlacement}\n >\n {buttonAriaLabel}\n </Hint>\n )}\n </>,\n );\n }}\n </NeighborLocation.Detect>\n );\n }\n}\n"],"mappings":";;AAAA,SAASA,gBAAgB,EAAEC,GAAG,EAAEC,IAAI,QAAQ,0BAA0B;AACtE,SAASC,SAAS,EAAEC,aAAa,EAAEC,IAAI,EAAEC,OAAO,QAAQ,eAAe;AACvE,OAAOC,iBAAiB,MAAM,2CAA2C;AACzE,OAAOC,SAAS,MAAM,mCAAmC;AACzD,OAAOC,MAAM,MAAM,gCAAgC;AACnD,OAAOC,KAAK,MAAM,OAAO;AAGzB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IAAI;QAAA,SAASoC;MAAQ,EAAG,CAC9C,CAEF,CAAC,EACTK,QAAQ,iBACPtD,KAAA,CAAAwD,aAAA,CAAChE,IAAI,EAAAkE,KAAA,CAAAE,EAAA;QAAA,cACS,IAAI,CAACvC,YAAY;QAAA,WACpB,CAAC,GAAG,EAAE,EAAE,CAAC;QAAA,aACPyB;MAAa,IAEvBM,eACG,CAER,CAAC;IAEP,CACuB,CAAC;EAE9B;AACF;AAAC3C,eAAA,CA1IqBH,cAAc,iBACb,gBAAgB","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=AbstractButton.type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractButton.type.js","names":[],"sources":["../../../../src/component/AbstractButton/AbstractButton.type.ts"],"sourcesContent":["import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';\nimport type { PropGetterFn } from '@semcore/core';\nimport type React from 'react';\n\nexport type AbstractButtonProps<S, U, T> = BoxProps &\n NeighborItemProps & {\n /** Button activity state */\n active?: boolean;\n /** Disabled button state */\n disabled?: boolean;\n /** Loading button state */\n loading?: boolean;\n /** Tag for the left Addon */\n addonLeft?: React.ElementType;\n /** Tag for the right Addon */\n addonRight?: React.ElementType;\n /**\n * Placement for hint\n * @default top\n */\n hintPlacement?: SimpleHintPopperProps['placement'];\n\n /** Button size. Defined in Button.type or ButtonLink.type */\n size?: S;\n /** Button usage. Defined in Button.type or ButtonLink.type */\n use?: U;\n /** Button theme. Defined in Button.type or ButtonLink.type */\n theme?: T;\n };\n\nexport type AbstractButtonAddonProps<S> = BoxProps & {\n size?: S;\n};\n\nexport type AbstractButtonTextProps<S> = BoxProps & {\n size?: S;\n};\n\nexport type AbstractButtonContext = {\n getTextProps: PropGetterFn;\n getAddonProps: PropGetterFn;\n};\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpinButton.js","names":["Spin","React","SPIN_SIZE_MAP","xl","l","m","s","SpinButton","theme","size","others","createElement","_extends"],"sources":["../../../../src/component/AbstractButton/SpinButton.tsx"],"sourcesContent":["import Spin from '@semcore/spin';\nimport React from 'react';\n\nexport const SPIN_SIZE_MAP: Record<string, string> = {\n xl: 'm',\n l: 's',\n m: 'xs',\n s: 'xxs',\n};\n\nexport default function SpinButton({ theme, size, ...others }: any) {\n return (\n <Spin\n size={typeof size === 'string' ? SPIN_SIZE_MAP[size] : size}\n theme='currentColor'\n {...others}\n />\n );\n}\n"],"mappings":";AAAA,OAAOA,IAAI,MAAM,eAAe;AAChC,OAAOC,KAAK,MAAM,OAAO;AAEzB,OAAO,MAAMC,aAAqC,GAAG;EACnDC,EAAE,EAAE,GAAG;EACPC,CAAC,EAAE,GAAG;EACNC,CAAC,EAAE,IAAI;EACPC,CAAC,EAAE;AACL,CAAC;AAED,eAAe,SAASC,UAAUA,CAAC;EAAEC,KAAK;EAAEC,IAAI;EAAE,GAAGC;AAAY,CAAC,EAAE;EAClE,oBACET,KAAA,CAAAU,aAAA,CAACX,IAAI,EAAAY,QAAA;IACHH,IAAI,EAAE,OAAOA,IAAI,KAAK,QAAQ,GAAGP,aAAa,CAACO,IAAI,CAAC,GAAGA,IAAK;IAC5DD,KAAK,EAAC;EAAc,GAChBE,MAAM,CACX,CAAC;AAEN","ignoreList":[]}
@@ -1,119 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Component, CORE_INSTANCE, sstyled, assignProps } from "@semcore/core";
3
- import { NeighborLocation, Box, Hint } from "@semcore/base-components";
4
- import addonTextChildren from "@semcore/core/lib/utils/addonTextChildren";
5
- import hasLabels from "@semcore/core/lib/utils/hasLabels";
6
- import logger from "@semcore/core/lib/utils/logger";
7
- import React from "react";
8
- import SpinButton from "./SpinButton.mjs";
9
- const MAP_USE_DEFAULT_THEME = {
10
- primary: "info",
11
- secondary: "muted",
12
- tertiary: "info"
13
- };
14
- class AbstractButton extends Component {
15
- constructor(...args) {
16
- super(...args);
17
- _defineProperty(this, "containerRef", /* @__PURE__ */ React.createRef());
18
- _defineProperty(this, "state", {
19
- ariaLabelledByContent: null
20
- });
21
- }
22
- getTextProps() {
23
- const {
24
- size
25
- } = this.asProps;
26
- return {
27
- size
28
- };
29
- }
30
- getAddonProps() {
31
- const {
32
- size
33
- } = this.asProps;
34
- return {
35
- size
36
- };
37
- }
38
- componentDidMount() {
39
- if (process.env.NODE_ENV !== "production") {
40
- logger.warn(this.containerRef.current && !hasLabels(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);
41
- logger.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);
42
- }
43
- const ariaLabelledby = this.asProps["aria-labelledby"];
44
- if (ariaLabelledby) {
45
- setTimeout(() => {
46
- var _a;
47
- this.setState({
48
- ariaLabelledByContent: ((_a = document.getElementById(ariaLabelledby)) == null ? void 0 : _a.textContent) ?? ""
49
- });
50
- }, 0);
51
- }
52
- }
53
- render() {
54
- var _ref = this.asProps;
55
- const {
56
- styles,
57
- use,
58
- theme = typeof use === "string" && MAP_USE_DEFAULT_THEME[use],
59
- loading,
60
- disabled = loading,
61
- size,
62
- neighborLocation,
63
- children,
64
- title,
65
- ["aria-label"]: ariaLabel,
66
- Children,
67
- addonLeft: AddonLeft,
68
- addonRight: AddonRight,
69
- hintPlacement
70
- } = this.asProps;
71
- const SButton = Box;
72
- const Button = this[CORE_INSTANCE];
73
- const useTheme = use && theme ? `${use}-${theme}` : false;
74
- const SInner = Box;
75
- const SSpin = Box;
76
- const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? "";
77
- const showHint = children === void 0 || title;
78
- return /* @__PURE__ */ React.createElement(NeighborLocation.Detect, {
79
- neighborLocation
80
- }, (neighborLocation2) => {
81
- var _ref2;
82
- return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SButton, _ref2.cn("SButton", {
83
- ...assignProps({
84
- "invertOutline": theme === "invert",
85
- "type": "button",
86
- "tag": "button",
87
- "tabIndex": 0,
88
- "disabled": disabled,
89
- "use:theme": useTheme,
90
- "ref": this.containerRef,
91
- "text-color": this.getTextColor(),
92
- "aria-busy": loading,
93
- "__excludeProps": ["title"],
94
- "aria-label": showHint ? buttonAriaLabel : void 0,
95
- "neighborLocation": neighborLocation2
96
- }, _ref)
97
- }), /* @__PURE__ */ React.createElement(SInner, _ref2.cn("SInner", {
98
- "tag": "span",
99
- "loading": loading,
100
- "data-ui-name": `${this.asProps["data-ui-name"]}.InnerWrapper`
101
- }), AddonLeft ? /* @__PURE__ */ React.createElement(Button.Addon, null, /* @__PURE__ */ React.createElement(AddonLeft, _ref2.cn("AddonLeft", {}))) : null, addonTextChildren(Children, Button.Text, Button.Addon), AddonRight ? /* @__PURE__ */ React.createElement(Button.Addon, null, /* @__PURE__ */ React.createElement(AddonRight, _ref2.cn("AddonRight", {}))) : null), loading && /* @__PURE__ */ React.createElement(SSpin, _ref2.cn("SSpin", {
102
- "tag": "span"
103
- }), /* @__PURE__ */ React.createElement(SpinButton, _ref2.cn("SpinButton", {
104
- "centered": true,
105
- "size": size,
106
- "theme": useTheme
107
- })))), showHint && /* @__PURE__ */ React.createElement(Hint, _ref2.cn("Hint", {
108
- "triggerRef": this.containerRef,
109
- "timeout": [250, 50],
110
- "placement": hintPlacement
111
- }), buttonAriaLabel));
112
- });
113
- }
114
- }
115
- _defineProperty(AbstractButton, "displayName", "AbstractButton");
116
- export {
117
- AbstractButton,
118
- MAP_USE_DEFAULT_THEME
119
- };
@@ -1,23 +0,0 @@
1
- import { Component } from '@semcore/core';
2
- import React from 'react';
3
- import type { AbstractButtonProps } from './AbstractButton.type';
4
- export declare const MAP_USE_DEFAULT_THEME: Record<string, string>;
5
- type Props = AbstractButtonProps<any, any, any>;
6
- type State = {
7
- ariaLabelledByContent: null | string;
8
- };
9
- export declare abstract class AbstractButton extends Component<Props, [], never, {}, State> {
10
- static displayName: string;
11
- containerRef: React.RefObject<HTMLButtonElement>;
12
- state: State;
13
- protected abstract getTextColor(): string | undefined;
14
- getTextProps(): {
15
- size: any;
16
- };
17
- getAddonProps(): {
18
- size: any;
19
- };
20
- componentDidMount(): void;
21
- render(): React.JSX.Element;
22
- }
23
- export {};
@@ -1,36 +0,0 @@
1
- import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';
2
- import type { PropGetterFn } from '@semcore/core';
3
- import type React from 'react';
4
- export type AbstractButtonProps<S, U, T> = BoxProps & NeighborItemProps & {
5
- /** Button activity state */
6
- active?: boolean;
7
- /** Disabled button state */
8
- disabled?: boolean;
9
- /** Loading button state */
10
- loading?: boolean;
11
- /** Tag for the left Addon */
12
- addonLeft?: React.ElementType;
13
- /** Tag for the right Addon */
14
- addonRight?: React.ElementType;
15
- /**
16
- * Placement for hint
17
- * @default top
18
- */
19
- hintPlacement?: SimpleHintPopperProps['placement'];
20
- /** Button size. Defined in Button.type or ButtonLink.type */
21
- size?: S;
22
- /** Button usage. Defined in Button.type or ButtonLink.type */
23
- use?: U;
24
- /** Button theme. Defined in Button.type or ButtonLink.type */
25
- theme?: T;
26
- };
27
- export type AbstractButtonAddonProps<S> = BoxProps & {
28
- size?: S;
29
- };
30
- export type AbstractButtonTextProps<S> = BoxProps & {
31
- size?: S;
32
- };
33
- export type AbstractButtonContext = {
34
- getTextProps: PropGetterFn;
35
- getAddonProps: PropGetterFn;
36
- };
@@ -1,161 +0,0 @@
1
- import { NeighborLocation, Box, Hint } from '@semcore/base-components';
2
- import { Component, CORE_INSTANCE, 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 React from 'react';
7
-
8
- import type { AbstractButtonProps } from './AbstractButton.type';
9
- import SpinButton from './SpinButton';
10
-
11
- export const MAP_USE_DEFAULT_THEME: Record<string, string> = {
12
- primary: 'info',
13
- secondary: 'muted',
14
- tertiary: 'info',
15
- };
16
-
17
- type Props = AbstractButtonProps<any, any, any>;
18
-
19
- type State = {
20
- ariaLabelledByContent: null | string;
21
- };
22
-
23
- export abstract class AbstractButton extends Component<Props, [], never, {}, State> {
24
- static displayName = 'AbstractButton';
25
-
26
- containerRef = React.createRef<HTMLButtonElement>();
27
-
28
- state: State = {
29
- ariaLabelledByContent: null,
30
- };
31
-
32
- protected abstract getTextColor(): string | undefined;
33
-
34
- getTextProps() {
35
- const { size } = this.asProps;
36
-
37
- return {
38
- size,
39
- };
40
- }
41
-
42
- getAddonProps() {
43
- const { size } = this.asProps;
44
- return {
45
- size,
46
- };
47
- }
48
-
49
- componentDidMount() {
50
- if (process.env.NODE_ENV !== 'production') {
51
- logger.warn(
52
- this.containerRef.current && !hasLabels(this.containerRef.current) && !this.asProps.title,
53
- `'title' or 'aria-label' or 'aria-labelledby' are required props for buttons without text content`,
54
- this.asProps['data-ui-name'] || AbstractButton.displayName,
55
- );
56
-
57
- logger.warn(
58
- this.asProps.theme === 'warning',
59
- 'Warning theme is deprecated and will be removed in the next major release.',
60
- this.asProps['data-ui-name'] || AbstractButton.displayName,
61
- );
62
- }
63
-
64
- const ariaLabelledby = this.asProps['aria-labelledby'];
65
-
66
- if (ariaLabelledby) {
67
- setTimeout(() => {
68
- this.setState({
69
- ariaLabelledByContent: document.getElementById(ariaLabelledby)?.textContent ?? '',
70
- });
71
- }, 0);
72
- }
73
- }
74
-
75
- render() {
76
- const {
77
- styles,
78
- use,
79
- theme = typeof use === 'string' && MAP_USE_DEFAULT_THEME[use],
80
- loading,
81
- disabled = loading,
82
- size,
83
- neighborLocation,
84
- children,
85
- title,
86
- ['aria-label']: ariaLabel,
87
- Children,
88
- addonLeft: AddonLeft,
89
- addonRight: AddonRight,
90
- hintPlacement,
91
- } = this.asProps;
92
- const SButton = Root;
93
- // @ts-ignore
94
- const Button = this[CORE_INSTANCE];
95
- const useTheme = use && theme ? `${use}-${theme}` : false;
96
- const SInner = Box;
97
- const SSpin = Box;
98
- const buttonAriaLabel = title ?? ariaLabel ?? this.state.ariaLabelledByContent ?? '';
99
-
100
- const showHint = (children === undefined || title);
101
-
102
- return (
103
- <NeighborLocation.Detect neighborLocation={neighborLocation}>
104
- {(neighborLocation) => {
105
- return sstyled(styles)(
106
- <>
107
- <SButton
108
- render={Box}
109
- invertOutline={theme === 'invert'}
110
- type='button'
111
- tag='button'
112
- tabIndex={0}
113
- disabled={disabled}
114
- use:theme={useTheme}
115
- ref={this.containerRef}
116
- text-color={this.getTextColor()}
117
- aria-busy={loading}
118
- __excludeProps={['title']}
119
- aria-label={showHint ? buttonAriaLabel : undefined}
120
- neighborLocation={neighborLocation}
121
- >
122
- {/* @ts-ignore */}
123
- <SInner tag='span' loading={loading} data-ui-name={`${this.asProps['data-ui-name']}.InnerWrapper`}>
124
- {AddonLeft
125
- ? (
126
- <Button.Addon>
127
- <AddonLeft />
128
- </Button.Addon>
129
- )
130
- : null}
131
- {addonTextChildren(Children, Button.Text, Button.Addon)}
132
- {AddonRight
133
- ? (
134
- <Button.Addon>
135
- <AddonRight />
136
- </Button.Addon>
137
- )
138
- : null}
139
- </SInner>
140
- {loading && (
141
- <SSpin tag='span'>
142
- <SpinButton centered size={size} theme={useTheme} />
143
- </SSpin>
144
- )}
145
- </SButton>
146
- {showHint && (
147
- <Hint
148
- triggerRef={this.containerRef}
149
- timeout={[250, 50]}
150
- placement={hintPlacement}
151
- >
152
- {buttonAriaLabel}
153
- </Hint>
154
- )}
155
- </>,
156
- );
157
- }}
158
- </NeighborLocation.Detect>
159
- );
160
- }
161
- }
@@ -1,42 +0,0 @@
1
- import type { BoxProps, NeighborItemProps, SimpleHintPopperProps } from '@semcore/base-components';
2
- import type { PropGetterFn } from '@semcore/core';
3
- import type React from 'react';
4
-
5
- export type AbstractButtonProps<S, U, T> = BoxProps &
6
- NeighborItemProps & {
7
- /** Button activity state */
8
- active?: boolean;
9
- /** Disabled button state */
10
- disabled?: boolean;
11
- /** Loading button state */
12
- loading?: boolean;
13
- /** Tag for the left Addon */
14
- addonLeft?: React.ElementType;
15
- /** Tag for the right Addon */
16
- addonRight?: React.ElementType;
17
- /**
18
- * Placement for hint
19
- * @default top
20
- */
21
- hintPlacement?: SimpleHintPopperProps['placement'];
22
-
23
- /** Button size. Defined in Button.type or ButtonLink.type */
24
- size?: S;
25
- /** Button usage. Defined in Button.type or ButtonLink.type */
26
- use?: U;
27
- /** Button theme. Defined in Button.type or ButtonLink.type */
28
- theme?: T;
29
- };
30
-
31
- export type AbstractButtonAddonProps<S> = BoxProps & {
32
- size?: S;
33
- };
34
-
35
- export type AbstractButtonTextProps<S> = BoxProps & {
36
- size?: S;
37
- };
38
-
39
- export type AbstractButtonContext = {
40
- getTextProps: PropGetterFn;
41
- getAddonProps: PropGetterFn;
42
- };