@skbkontur/react-ui 4.8.0 → 4.9.0
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/CHANGELOG.md +19 -0
- package/cjs/components/DatePicker/DatePicker.d.ts +11 -12
- package/cjs/components/DatePicker/DatePicker.js +0 -2
- package/cjs/components/DatePicker/DatePicker.js.map +1 -1
- package/cjs/components/Group/Group.d.ts +1 -0
- package/cjs/components/Group/Group.js +7 -11
- package/cjs/components/Group/Group.js.map +1 -1
- package/cjs/components/MenuItem/MenuItem.d.ts +1 -1
- package/cjs/components/MenuItem/MenuItem.js.map +1 -1
- package/cjs/components/Modal/ModalFooter.d.ts +14 -0
- package/cjs/components/Modal/ModalFooter.js +22 -1
- package/cjs/components/Modal/ModalFooter.js.map +1 -1
- package/cjs/components/RadioGroup/RadioGroup.d.ts +0 -14
- package/cjs/components/RadioGroup/RadioGroup.js +1 -16
- package/cjs/components/RadioGroup/RadioGroup.js.map +1 -1
- package/cjs/components/Select/Select.d.ts +1 -24
- package/cjs/components/Select/Select.js +2 -25
- package/cjs/components/Select/Select.js.map +1 -1
- package/cjs/components/SidePage/SidePageFooter.d.ts +9 -1
- package/cjs/components/SidePage/SidePageFooter.js +16 -1
- package/cjs/components/SidePage/SidePageFooter.js.map +1 -1
- package/cjs/components/SidePage/SidePageHeader.d.ts +1 -1
- package/cjs/components/SidePage/SidePageHeader.js.map +1 -1
- package/cjs/components/Sticky/Sticky.d.ts +1 -1
- package/cjs/components/Sticky/Sticky.js.map +1 -1
- package/cjs/components/Switcher/Switcher.d.ts +7 -0
- package/cjs/components/Switcher/Switcher.js +34 -10
- package/cjs/components/Switcher/Switcher.js.map +1 -1
- package/cjs/components/Switcher/Switcher.md +97 -0
- package/cjs/components/Tabs/Tab.d.ts +0 -8
- package/cjs/components/Tabs/Tab.js +1 -10
- package/cjs/components/Tabs/Tab.js.map +1 -1
- package/cjs/components/Tabs/Tabs.d.ts +0 -8
- package/cjs/components/Tabs/Tabs.js +1 -9
- package/cjs/components/Tabs/Tabs.js.map +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +54 -54
- package/cjs/index.js.map +1 -1
- package/cjs/internal/Popup/Popup.d.ts +1 -1
- package/cjs/internal/Popup/Popup.js.map +1 -1
- package/cjs/internal/ThemePlayground/AnotherInputsPlayground.d.ts +1 -1
- package/cjs/internal/ThemePlayground/AnotherInputsPlayground.js.map +1 -1
- package/cjs/lib/theming/ThemeContext.md +18 -12
- package/components/DatePicker/DatePicker/DatePicker.js.map +1 -1
- package/components/DatePicker/DatePicker.d.ts +11 -12
- package/components/Group/Group/Group.js +5 -5
- package/components/Group/Group/Group.js.map +1 -1
- package/components/Group/Group.d.ts +1 -0
- package/components/MenuItem/MenuItem/MenuItem.js.map +1 -1
- package/components/MenuItem/MenuItem.d.ts +1 -1
- package/components/Modal/ModalFooter/ModalFooter.js +7 -1
- package/components/Modal/ModalFooter/ModalFooter.js.map +1 -1
- package/components/Modal/ModalFooter.d.ts +14 -0
- package/components/RadioGroup/RadioGroup/RadioGroup.js +1 -14
- package/components/RadioGroup/RadioGroup/RadioGroup.js.map +1 -1
- package/components/RadioGroup/RadioGroup.d.ts +0 -14
- package/components/Select/Select/Select.js +1 -23
- package/components/Select/Select/Select.js.map +1 -1
- package/components/Select/Select.d.ts +1 -24
- package/components/SidePage/SidePageFooter/SidePageFooter.js +6 -1
- package/components/SidePage/SidePageFooter/SidePageFooter.js.map +1 -1
- package/components/SidePage/SidePageFooter.d.ts +9 -1
- package/components/SidePage/SidePageHeader/SidePageHeader.js.map +1 -1
- package/components/SidePage/SidePageHeader.d.ts +1 -1
- package/components/Sticky/Sticky/Sticky.js.map +1 -1
- package/components/Sticky/Sticky.d.ts +1 -1
- package/components/Switcher/Switcher/Switcher.js +30 -11
- package/components/Switcher/Switcher/Switcher.js.map +1 -1
- package/components/Switcher/Switcher.d.ts +7 -0
- package/components/Switcher/Switcher.md +97 -0
- package/components/Tabs/Tab/Tab.js +1 -8
- package/components/Tabs/Tab/Tab.js.map +1 -1
- package/components/Tabs/Tab.d.ts +0 -8
- package/components/Tabs/Tabs/Tabs.js +1 -8
- package/components/Tabs/Tabs/Tabs.js.map +1 -1
- package/components/Tabs/Tabs.d.ts +0 -8
- package/index.d.ts +2 -0
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/internal/Popup/Popup/Popup.js.map +1 -1
- package/internal/Popup/Popup.d.ts +1 -1
- package/internal/ThemePlayground/AnotherInputsPlayground/AnotherInputsPlayground.js.map +1 -1
- package/internal/ThemePlayground/AnotherInputsPlayground.d.ts +1 -1
- package/lib/theming/ThemeContext.md +18 -12
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ var _class, _class2, _temp;
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from "../../../lib/events/keyboard/identifiers";
|
|
9
|
-
import { Group } from "../../Group";
|
|
9
|
+
import { getButtonCorners, Group } from "../../Group";
|
|
10
10
|
import { Button } from "../../Button";
|
|
11
11
|
import { ThemeContext } from "../../../lib/theming/ThemeContext";
|
|
12
12
|
import { CommonWrapper } from "../../../internal/CommonWrapper";
|
|
@@ -125,28 +125,46 @@ export var Switcher = rootNode(_class = (_temp = _class2 = /*#__PURE__*/function
|
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
_this._renderItems = function () {
|
|
128
|
-
|
|
128
|
+
var _this$props = _this.props,
|
|
129
|
+
items = _this$props.items,
|
|
130
|
+
value = _this$props.value,
|
|
131
|
+
size = _this$props.size,
|
|
132
|
+
disabled = _this$props.disabled,
|
|
133
|
+
renderItem = _this$props.renderItem;
|
|
134
|
+
return items.map(function (item, i) {
|
|
129
135
|
var _this$_extractPropsFr3 = _this._extractPropsFromItem(item),
|
|
130
136
|
label = _this$_extractPropsFr3.label,
|
|
131
|
-
|
|
137
|
+
itemValue = _this$_extractPropsFr3.value,
|
|
132
138
|
customButtonProps = _this$_extractPropsFr3.buttonProps;
|
|
133
139
|
|
|
134
140
|
var commonButtonProps = {
|
|
135
|
-
checked:
|
|
141
|
+
checked: value === itemValue,
|
|
136
142
|
visuallyFocused: _this.state.focusedIndex === i,
|
|
137
143
|
onClick: function onClick() {
|
|
138
|
-
_this.selectItem(
|
|
144
|
+
_this.selectItem(itemValue);
|
|
139
145
|
},
|
|
140
146
|
disableFocus: true,
|
|
141
|
-
size:
|
|
142
|
-
disabled:
|
|
147
|
+
size: size,
|
|
148
|
+
disabled: disabled,
|
|
149
|
+
corners: getButtonCorners(i === 0, i === items.length - 1)
|
|
143
150
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
|
|
152
|
+
var buttonProps = _extends({}, commonButtonProps, customButtonProps);
|
|
153
|
+
|
|
154
|
+
var renderDefault = function renderDefault() {
|
|
155
|
+
return _this.renderDefaultItem(label, itemValue, buttonProps);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return renderItem ? renderItem(label, itemValue, buttonProps, renderDefault) : renderDefault();
|
|
147
159
|
});
|
|
148
160
|
};
|
|
149
161
|
|
|
162
|
+
_this.renderDefaultItem = function (label, value, buttonProps) {
|
|
163
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
164
|
+
key: value
|
|
165
|
+
}, buttonProps), label);
|
|
166
|
+
};
|
|
167
|
+
|
|
150
168
|
_this.getLabelSizeClassName = function () {
|
|
151
169
|
switch (_this.props.size) {
|
|
152
170
|
case 'large':
|
|
@@ -213,5 +231,6 @@ export var Switcher = rootNode(_class = (_temp = _class2 = /*#__PURE__*/function
|
|
|
213
231
|
}))]).isRequired,
|
|
214
232
|
caption: PropTypes.string,
|
|
215
233
|
value: PropTypes.string,
|
|
216
|
-
onValueChange: PropTypes.func
|
|
234
|
+
onValueChange: PropTypes.func,
|
|
235
|
+
renderItem: PropTypes.func
|
|
217
236
|
}, _temp)) || _class;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Switcher.tsx"],"names":["React","PropTypes","isKeyArrowHorizontal","isKeyArrowLeft","isKeyEnter","Group","Button","ThemeContext","CommonWrapper","cx","rootNode","styles","getSwitcherTheme","SwitcherDataTids","root","Switcher","state","focusedIndex","selectItem","value","props","onValueChange","_extractPropsFromItem","item","label","_extractValuesFromItems","items","map","move","step","selectedIndex","length","_focus","index","setState","handleKey","e","preventDefault","_handleFocus","currentIndex","indexOf","_handleBlur","_renderItems","i","customButtonProps","buttonProps","commonButtonProps","checked","visuallyFocused","onClick","disableFocus","size","disabled","getLabelSizeClassName","captionLarge","theme","captionMedium","captionSmall","render","renderMain","listClassName","error","inputProps","type","onKeyDown","onFocus","onBlur","className","input","captionClassName","caption","setRootNode","wrap","Component","__KONTUR_REACT_UI__","propTypes","bool","oneOfType","arrayOf","string","shape","isRequired","func"],"mappings":"2JAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;;AAEA,SAASC,oBAAT,EAA+BC,cAA/B,EAA+CC,UAA/C,QAAiE,uCAAjE;AACA,SAASC,KAAT,QAAsB,UAAtB;AACA,SAASC,MAAT,QAAgD,WAAhD;;AAEA,SAASC,YAAT,QAA6B,gCAA7B;;AAEA,SAAsBC,aAAtB,QAA2C,8BAA3C;AACA,SAASC,EAAT,QAAmB,2BAAnB;AACA,SAASC,QAAT,QAAuC,oBAAvC;;AAEA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SAASC,gBAAT,QAAiC,iBAAjC;;;;;AAKA,OAAO,IAAMC,gBAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,gBADwB,EAAzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCP,WAAaC,QAAb,GADCL,QACD;;;;;;;;;;;;;;;;;;;;AAoBSM,IAAAA,KApBT,GAoBgC;AAC5BC,MAAAA,YAAY,EAAE,IADc,EApBhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAExBxB,QAAQ,EAAEnD,SAAS,CAAC2E,IAFI,EAGxBlD,KAAK,EAAEzB,SAAS,CAAC4E,SAAV,CAAoB,CACzB5E,SAAS,CAAC6E,OAAV,CAAkB7E,SAAS,CAAC8E,MAA5B,CADyB,EAEzB9E,SAAS,CAAC6E,OAAV,CACE7E,SAAS,CAAC+E,KAAV,CAAgB,EACdxD,KAAK,EAAEvB,SAAS,CAAC8E,MADH,EAEd5D,KAAK,EAAElB,SAAS,CAAC8E,MAFH,EAAhB,CADF,CAFyB,CAApB,EAQJE,UAXqB,EAYxBX,OAAO,EAAErE,SAAS,CAAC8E,MAZK,EAaxB5D,KAAK,EAAElB,SAAS,CAAC8E,MAbO,EAcxB1D,aAAa,EAAEpB,SAAS,CAACiF,IAdD,EAH5B","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from '../../lib/events/keyboard/identifiers';\nimport { Group } from '../Group';\nimport { Button, ButtonProps, ButtonSize } from '../Button';\nimport { Nullable } from '../../typings/utility-types';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\n\nimport { styles } from './Switcher.styles';\nimport { getSwitcherTheme } from './switcherTheme';\n\nexport type SwitcherSize = ButtonSize;\ntype SwitcherItems = string | SwitcherItem;\n\nexport const SwitcherDataTids = {\n root: 'Switcher__root',\n} as const;\n\nexport interface SwitcherProps extends CommonProps {\n /**\n * Список строк или список элементов типа `{ label: string, value: string, buttonProps?: Partial<ButtonProps> }`\n */\n items: SwitcherItems[];\n\n value?: string;\n\n onValueChange?: (value: string) => void;\n\n caption?: string;\n\n error?: boolean;\n\n /** Размер */\n size?: SwitcherSize;\n\n disabled?: boolean;\n}\n\nexport interface SwitcherState {\n focusedIndex: Nullable<number>;\n}\n\ninterface SwitcherItem {\n label: string;\n value: string;\n buttonProps?: Partial<ButtonProps>;\n}\n\n@rootNode\nexport class Switcher extends React.Component<SwitcherProps, SwitcherState> {\n public static __KONTUR_REACT_UI__ = 'Switcher';\n\n public static propTypes = {\n error: PropTypes.bool,\n disabled: PropTypes.bool,\n items: PropTypes.oneOfType([\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.arrayOf(\n PropTypes.shape({\n label: PropTypes.string,\n value: PropTypes.string,\n }),\n ),\n ]).isRequired,\n caption: PropTypes.string,\n value: PropTypes.string,\n onValueChange: PropTypes.func,\n };\n\n public state: SwitcherState = {\n focusedIndex: null,\n };\n\n private theme!: Theme;\n private setRootNode!: TSetRootNode;\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = getSwitcherTheme(theme);\n return <ThemeContext.Provider value={this.theme}>{this.renderMain()}</ThemeContext.Provider>;\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const listClassName = cx({\n [styles.error(this.theme)]: !!this.props.error,\n });\n\n const inputProps = {\n type: 'checkbox',\n onKeyDown: this.handleKey,\n onFocus: this._handleFocus,\n onBlur: this._handleBlur,\n className: styles.input(),\n };\n\n const captionClassName = cx(styles.caption(this.theme), this.getLabelSizeClassName());\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div data-tid={SwitcherDataTids.root} className={styles.root()}>\n {this.props.caption ? <div className={captionClassName}>{this.props.caption}</div> : null}\n <div className={styles.wrap()}>\n <input {...inputProps} />\n <div className={listClassName}>\n <Group>{this._renderItems()}</Group>\n </div>\n </div>\n </div>\n </CommonWrapper>\n );\n }\n\n private selectItem = (value: string) => {\n if (this.props.onValueChange) {\n this.props.onValueChange(value);\n }\n };\n\n private _extractPropsFromItem = (item: string | SwitcherItem): SwitcherItem => {\n return typeof item === 'object' ? item : { label: item, value: item };\n };\n\n private _extractValuesFromItems = (): string[] => {\n return this.props.items.map((item) => {\n const { value } = this._extractPropsFromItem(item);\n return value;\n });\n };\n\n private move = (step: number) => {\n let selectedIndex = this.state.focusedIndex;\n\n if (typeof selectedIndex !== 'number') {\n return;\n }\n\n const items = this._extractValuesFromItems();\n\n selectedIndex += step;\n\n if (selectedIndex < 0) {\n selectedIndex = items.length - 1;\n } else if (selectedIndex >= items.length) {\n selectedIndex = 0;\n }\n\n this._focus(selectedIndex);\n };\n\n private _focus = (index: number) => {\n this.setState({ focusedIndex: index });\n };\n\n private handleKey = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const focusedIndex = this.state.focusedIndex;\n if (typeof focusedIndex !== 'number') {\n return;\n }\n\n if (isKeyEnter(e)) {\n if (this.props.onValueChange) {\n const { value } = this._extractPropsFromItem(this.props.items[focusedIndex]);\n this.selectItem(value);\n }\n return;\n }\n\n if (isKeyArrowHorizontal(e)) {\n e.preventDefault();\n this.move(isKeyArrowLeft(e) ? -1 : 1);\n }\n };\n\n private _handleFocus = () => {\n const { value } = this.props;\n\n const items = this._extractValuesFromItems();\n const currentIndex = [...items].indexOf(value as string);\n const index = currentIndex > -1 ? currentIndex : 0;\n\n this.setState({ focusedIndex: index });\n };\n\n private _handleBlur = () => {\n this.setState({ focusedIndex: null });\n };\n\n private _renderItems = () => {\n return this.props.items.map((item, i) => {\n const { label, value, buttonProps: customButtonProps } = this._extractPropsFromItem(item);\n const commonButtonProps = {\n checked: this.props.value === value,\n visuallyFocused: this.state.focusedIndex === i,\n onClick: () => {\n this.selectItem(value);\n },\n disableFocus: true,\n size: this.props.size,\n disabled: this.props.disabled,\n };\n return (\n <Button key={value} {...commonButtonProps} {...customButtonProps}>\n {label}\n </Button>\n );\n });\n };\n\n private getLabelSizeClassName = (): string => {\n switch (this.props.size) {\n case 'large':\n return styles.captionLarge(this.theme);\n case 'medium':\n return styles.captionMedium(this.theme);\n case 'small':\n default:\n return styles.captionSmall(this.theme);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["Switcher.tsx"],"names":["React","PropTypes","isKeyArrowHorizontal","isKeyArrowLeft","isKeyEnter","getButtonCorners","Group","Button","ThemeContext","CommonWrapper","cx","rootNode","styles","getSwitcherTheme","SwitcherDataTids","root","Switcher","state","focusedIndex","selectItem","value","props","onValueChange","_extractPropsFromItem","item","label","_extractValuesFromItems","items","map","move","step","selectedIndex","length","_focus","index","setState","handleKey","e","preventDefault","_handleFocus","currentIndex","indexOf","_handleBlur","_renderItems","size","disabled","renderItem","i","itemValue","customButtonProps","buttonProps","commonButtonProps","checked","visuallyFocused","onClick","disableFocus","corners","renderDefault","renderDefaultItem","getLabelSizeClassName","captionLarge","theme","captionMedium","captionSmall","render","renderMain","listClassName","error","inputProps","type","onKeyDown","onFocus","onBlur","className","input","captionClassName","caption","setRootNode","wrap","Component","__KONTUR_REACT_UI__","propTypes","bool","oneOfType","arrayOf","string","shape","isRequired","func"],"mappings":"2JAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;;AAEA,SAASC,oBAAT,EAA+BC,cAA/B,EAA+CC,UAA/C,QAAiE,uCAAjE;AACA,SAASC,gBAAT,EAA2BC,KAA3B,QAAwC,UAAxC;AACA,SAASC,MAAT,QAAgD,WAAhD;;AAEA,SAASC,YAAT,QAA6B,gCAA7B;;AAEA,SAAsBC,aAAtB,QAA2C,8BAA3C;AACA,SAASC,EAAT,QAAmB,2BAAnB;AACA,SAASC,QAAT,QAAuC,oBAAvC;;AAEA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SAASC,gBAAT,QAAiC,iBAAjC;;;;;AAKA,OAAO,IAAMC,gBAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,gBADwB,EAAzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CP,WAAaC,QAAb,GADCL,QACD;;;;;;;;;;;;;;;;;;;;;AAqBSM,IAAAA,KArBT,GAqBgC;AAC5BC,MAAAA,YAAY,EAAE,IADc,EArBhC;;;;;;;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A7B,CAA3B,CAEA,oBACE,oBAAC,aAAD,aAAe,WAAW,EAAE,KAAKkB,WAAjC,IAAkD,KAAKxD,KAAvD,gBACE,6BAAK,YAAUP,gBAAgB,CAACC,IAAhC,EAAsC,SAAS,EAAEH,MAAM,CAACG,IAAP,EAAjD,IACG,KAAKM,KAAL,CAAWuD,OAAX,gBAAqB,6BAAK,SAAS,EAAED,gBAAhB,IAAmC,KAAKtD,KAAL,CAAWuD,OAA9C,CAArB,GAAoF,IADvF,eAEE,6BAAK,SAAS,EAAEhE,MAAM,CAACkE,IAAP,EAAhB,iBACE,6BAAWV,UAAX,CADF,eAEE,6BAAK,SAAS,EAAEF,aAAhB,iBACE,oBAAC,KAAD,QAAQ,KAAKvB,YAAL,EAAR,CADF,CAFF,CAFF,CADF,CADF,CAaD,CAnEH,mBAA8B3C,KAAK,CAAC+E,SAApC,WACgBC,mBADhB,GACsC,UADtC,UAGgBC,SAHhB,GAG4B,EACxBd,KAAK,EAAElE,SAAS,CAACiF,IADO,EAExBrC,QAAQ,EAAE5C,SAAS,CAACiF,IAFI,EAGxBvD,KAAK,EAAE1B,SAAS,CAACkF,SAAV,CAAoB,CACzBlF,SAAS,CAACmF,OAAV,CAAkBnF,SAAS,CAACoF,MAA5B,CADyB,EAEzBpF,SAAS,CAACmF,OAAV,CACEnF,SAAS,CAACqF,KAAV,CAAgB,EACd7D,KAAK,EAAExB,SAAS,CAACoF,MADH,EAEdjE,KAAK,EAAEnB,SAAS,CAACoF,MAFH,EAAhB,CADF,CAFyB,CAApB,EAQJE,UAXqB,EAYxBX,OAAO,EAAE3E,SAAS,CAACoF,MAZK,EAaxBjE,KAAK,EAAEnB,SAAS,CAACoF,MAbO,EAcxB/D,aAAa,EAAErB,SAAS,CAACuF,IAdD,EAexB1C,UAAU,EAAE7C,SAAS,CAACuF,IAfE,EAH5B","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from '../../lib/events/keyboard/identifiers';\nimport { getButtonCorners, Group } from '../Group';\nimport { Button, ButtonProps, ButtonSize } from '../Button';\nimport { Nullable } from '../../typings/utility-types';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\n\nimport { styles } from './Switcher.styles';\nimport { getSwitcherTheme } from './switcherTheme';\n\nexport type SwitcherSize = ButtonSize;\ntype SwitcherItems = string | SwitcherItem;\n\nexport const SwitcherDataTids = {\n root: 'Switcher__root',\n} as const;\n\nexport interface SwitcherProps extends CommonProps {\n /**\n * Список строк или список элементов типа `{ label: string, value: string, buttonProps?: Partial<ButtonProps> }`\n */\n items: SwitcherItems[];\n\n value?: string;\n\n onValueChange?: (value: string) => void;\n\n caption?: string;\n\n error?: boolean;\n\n /** Размер */\n size?: SwitcherSize;\n\n disabled?: boolean;\n\n /**\n * Функция для отрисовки элемента. Аргументы — `label`,\n * `value`, `buttonProps`, `renderDefault`\n */\n renderItem?: (\n label: string,\n value: string,\n buttonProps: ButtonProps,\n renderDefault: () => React.ReactNode,\n ) => React.ReactNode;\n}\n\nexport interface SwitcherState {\n focusedIndex: Nullable<number>;\n}\n\ninterface SwitcherItem {\n label: string;\n value: string;\n buttonProps?: Partial<ButtonProps>;\n}\n\n@rootNode\nexport class Switcher extends React.Component<SwitcherProps, SwitcherState> {\n public static __KONTUR_REACT_UI__ = 'Switcher';\n\n public static propTypes = {\n error: PropTypes.bool,\n disabled: PropTypes.bool,\n items: PropTypes.oneOfType([\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.arrayOf(\n PropTypes.shape({\n label: PropTypes.string,\n value: PropTypes.string,\n }),\n ),\n ]).isRequired,\n caption: PropTypes.string,\n value: PropTypes.string,\n onValueChange: PropTypes.func,\n renderItem: PropTypes.func,\n };\n\n public state: SwitcherState = {\n focusedIndex: null,\n };\n\n private theme!: Theme;\n private setRootNode!: TSetRootNode;\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = getSwitcherTheme(theme);\n return <ThemeContext.Provider value={this.theme}>{this.renderMain()}</ThemeContext.Provider>;\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const listClassName = cx({\n [styles.error(this.theme)]: !!this.props.error,\n });\n\n const inputProps = {\n type: 'checkbox',\n onKeyDown: this.handleKey,\n onFocus: this._handleFocus,\n onBlur: this._handleBlur,\n className: styles.input(),\n };\n\n const captionClassName = cx(styles.caption(this.theme), this.getLabelSizeClassName());\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div data-tid={SwitcherDataTids.root} className={styles.root()}>\n {this.props.caption ? <div className={captionClassName}>{this.props.caption}</div> : null}\n <div className={styles.wrap()}>\n <input {...inputProps} />\n <div className={listClassName}>\n <Group>{this._renderItems()}</Group>\n </div>\n </div>\n </div>\n </CommonWrapper>\n );\n }\n\n private selectItem = (value: string) => {\n if (this.props.onValueChange) {\n this.props.onValueChange(value);\n }\n };\n\n private _extractPropsFromItem = (item: string | SwitcherItem): SwitcherItem => {\n return typeof item === 'object' ? item : { label: item, value: item };\n };\n\n private _extractValuesFromItems = (): string[] => {\n return this.props.items.map((item) => {\n const { value } = this._extractPropsFromItem(item);\n return value;\n });\n };\n\n private move = (step: number) => {\n let selectedIndex = this.state.focusedIndex;\n\n if (typeof selectedIndex !== 'number') {\n return;\n }\n\n const items = this._extractValuesFromItems();\n\n selectedIndex += step;\n\n if (selectedIndex < 0) {\n selectedIndex = items.length - 1;\n } else if (selectedIndex >= items.length) {\n selectedIndex = 0;\n }\n\n this._focus(selectedIndex);\n };\n\n private _focus = (index: number) => {\n this.setState({ focusedIndex: index });\n };\n\n private handleKey = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const focusedIndex = this.state.focusedIndex;\n if (typeof focusedIndex !== 'number') {\n return;\n }\n\n if (isKeyEnter(e)) {\n if (this.props.onValueChange) {\n const { value } = this._extractPropsFromItem(this.props.items[focusedIndex]);\n this.selectItem(value);\n }\n return;\n }\n\n if (isKeyArrowHorizontal(e)) {\n e.preventDefault();\n this.move(isKeyArrowLeft(e) ? -1 : 1);\n }\n };\n\n private _handleFocus = () => {\n const { value } = this.props;\n\n const items = this._extractValuesFromItems();\n const currentIndex = [...items].indexOf(value as string);\n const index = currentIndex > -1 ? currentIndex : 0;\n\n this.setState({ focusedIndex: index });\n };\n\n private _handleBlur = () => {\n this.setState({ focusedIndex: null });\n };\n\n private _renderItems = () => {\n const { items, value, size, disabled, renderItem } = this.props;\n return items.map((item, i) => {\n const { label, value: itemValue, buttonProps: customButtonProps } = this._extractPropsFromItem(item);\n const commonButtonProps = {\n checked: value === itemValue,\n visuallyFocused: this.state.focusedIndex === i,\n onClick: () => {\n this.selectItem(itemValue);\n },\n disableFocus: true,\n size,\n disabled,\n corners: getButtonCorners(i === 0, i === items.length - 1),\n };\n\n const buttonProps = {\n ...commonButtonProps,\n ...customButtonProps,\n };\n\n const renderDefault = () => this.renderDefaultItem(label, itemValue, buttonProps);\n\n return renderItem ? renderItem(label, itemValue, buttonProps, renderDefault) : renderDefault();\n });\n };\n\n private renderDefaultItem = (label: string, value: string, buttonProps: ButtonProps) => (\n <Button key={value} {...buttonProps}>\n {label}\n </Button>\n );\n\n private getLabelSizeClassName = (): string => {\n switch (this.props.size) {\n case 'large':\n return styles.captionLarge(this.theme);\n case 'medium':\n return styles.captionMedium(this.theme);\n case 'small':\n default:\n return styles.captionSmall(this.theme);\n }\n };\n}\n"]}
|
|
@@ -20,6 +20,11 @@ export interface SwitcherProps extends CommonProps {
|
|
|
20
20
|
/** Размер */
|
|
21
21
|
size?: SwitcherSize;
|
|
22
22
|
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Функция для отрисовки элемента. Аргументы — `label`,
|
|
25
|
+
* `value`, `buttonProps`, `renderDefault`
|
|
26
|
+
*/
|
|
27
|
+
renderItem?: (label: string, value: string, buttonProps: ButtonProps, renderDefault: () => React.ReactNode) => React.ReactNode;
|
|
23
28
|
}
|
|
24
29
|
export interface SwitcherState {
|
|
25
30
|
focusedIndex: Nullable<number>;
|
|
@@ -41,6 +46,7 @@ export declare class Switcher extends React.Component<SwitcherProps, SwitcherSta
|
|
|
41
46
|
caption: PropTypes.Requireable<string>;
|
|
42
47
|
value: PropTypes.Requireable<string>;
|
|
43
48
|
onValueChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
49
|
+
renderItem: PropTypes.Requireable<(...args: any[]) => any>;
|
|
44
50
|
};
|
|
45
51
|
state: SwitcherState;
|
|
46
52
|
private theme;
|
|
@@ -56,6 +62,7 @@ export declare class Switcher extends React.Component<SwitcherProps, SwitcherSta
|
|
|
56
62
|
private _handleFocus;
|
|
57
63
|
private _handleBlur;
|
|
58
64
|
private _renderItems;
|
|
65
|
+
private renderDefaultItem;
|
|
59
66
|
private getLabelSizeClassName;
|
|
60
67
|
}
|
|
61
68
|
export {};
|
|
@@ -8,3 +8,100 @@ const [value, setValue] = React.useState();
|
|
|
8
8
|
onValueChange={setValue}
|
|
9
9
|
/>;
|
|
10
10
|
```
|
|
11
|
+
|
|
12
|
+
Случай, когда `items` принимает объект типа `{ label: string, value: string }`:
|
|
13
|
+
|
|
14
|
+
```jsx harmony
|
|
15
|
+
const [value, setValue] = React.useState();
|
|
16
|
+
const items = [
|
|
17
|
+
{
|
|
18
|
+
label: 'One',
|
|
19
|
+
value: '111',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'Two',
|
|
23
|
+
value: '222',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: 'Three',
|
|
27
|
+
value: '333',
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
<Switcher
|
|
32
|
+
caption="Switch the switcher"
|
|
33
|
+
items={items}
|
|
34
|
+
value={value}
|
|
35
|
+
onValueChange={setValue}
|
|
36
|
+
/>;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Вариант `items` с полем `buttonProps`, который позволяет кастомизировать кнопку:
|
|
40
|
+
|
|
41
|
+
```jsx harmony
|
|
42
|
+
const [value, setValue] = React.useState();
|
|
43
|
+
const items = [
|
|
44
|
+
{
|
|
45
|
+
label: 'One',
|
|
46
|
+
value: '111',
|
|
47
|
+
buttonProps: {
|
|
48
|
+
'data-tid': "1-1-1",
|
|
49
|
+
disabled: true,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Three',
|
|
54
|
+
value: '333',
|
|
55
|
+
buttonProps: {
|
|
56
|
+
'data-tid': "1-1-1",
|
|
57
|
+
use: "primary",
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: 'Two',
|
|
62
|
+
value: '222',
|
|
63
|
+
buttonProps: {
|
|
64
|
+
'data-tid': "1-1-1",
|
|
65
|
+
arrow: true,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
<Switcher
|
|
71
|
+
caption="Switch the switcher"
|
|
72
|
+
items={items}
|
|
73
|
+
value={value}
|
|
74
|
+
onValueChange={setValue}
|
|
75
|
+
/>;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Пример с методом `renderItem` для кастомизации `items`:
|
|
79
|
+
|
|
80
|
+
```jsx harmony
|
|
81
|
+
import {Hint, Tooltip} from '@skbkontur/react-ui';
|
|
82
|
+
|
|
83
|
+
const [value, setValue] = React.useState();
|
|
84
|
+
const items = ['One', 'Two', 'Three'];
|
|
85
|
+
|
|
86
|
+
const renderItem = (label, value, buttonProps, renderDefault) => {
|
|
87
|
+
if (value === 'One') {
|
|
88
|
+
return <Hint pos="bottom" text="Подсказка" opened manual>{renderDefault()}</Hint>;
|
|
89
|
+
}
|
|
90
|
+
if (value === 'Three') {
|
|
91
|
+
return (
|
|
92
|
+
<Tooltip pos="right middle" trigger="opened" render={() => 'Тултип'}>
|
|
93
|
+
{renderDefault()}
|
|
94
|
+
</Tooltip>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return renderDefault();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
<Switcher
|
|
101
|
+
caption="Switch the switcher"
|
|
102
|
+
items={items}
|
|
103
|
+
value={value}
|
|
104
|
+
onValueChange={setValue}
|
|
105
|
+
renderItem={renderItem}
|
|
106
|
+
/>;
|
|
107
|
+
```
|
|
@@ -5,7 +5,6 @@ import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
|
5
5
|
var _class, _class2, _temp;
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
8
|
import invariant from 'invariant';
|
|
10
9
|
import { ResizeDetector } from "../../../internal/ResizeDetector";
|
|
11
10
|
import { isKeyArrow, isKeyArrowLeft, isKeyArrowUp } from "../../../lib/events/keyboard/identifiers";
|
|
@@ -243,13 +242,7 @@ var Tab = rootNode(_class = (_temp = _class2 = /*#__PURE__*/function (_React$Com
|
|
|
243
242
|
};
|
|
244
243
|
|
|
245
244
|
return Tab;
|
|
246
|
-
}(React.Component), _class2.__KONTUR_REACT_UI__ = 'Tab', _class2.contextType = TabsContext, _class2.
|
|
247
|
-
children: PropTypes.node,
|
|
248
|
-
disabled: PropTypes.bool,
|
|
249
|
-
href: PropTypes.string.isRequired,
|
|
250
|
-
onClick: PropTypes.func,
|
|
251
|
-
onKeyDown: PropTypes.func
|
|
252
|
-
}, _class2.defaultProps = {
|
|
245
|
+
}(React.Component), _class2.__KONTUR_REACT_UI__ = 'Tab', _class2.contextType = TabsContext, _class2.defaultProps = {
|
|
253
246
|
component: 'a',
|
|
254
247
|
href: ''
|
|
255
248
|
}, _temp)) || _class;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Tab.tsx"],"names":["React","PropTypes","invariant","ResizeDetector","isKeyArrow","isKeyArrowLeft","isKeyArrowUp","keyListener","isFunctionalComponent","ThemeContext","CommonWrapper","cx","rootNode","createPropsGetter","TabsContext","TabsContextDefaultValue","styles","horizontalStyles","verticalStyles","globalClasses","TabDataTids","root","Tab","props","context","getProps","defaultProps","state","focusedByKeyboard","tabComponent","getUnderlyingNode","getId","id","href","refTabComponent","instance","getTabInstance","switchTab","event","disabled","preventDefault","component","onClick","defaultPrevented","handleKeyDown","e","onKeyDown","delta","shiftFocus","handleFocus","requestAnimationFrame","isTabPressed","isArrowPressed","setState","handleBlur","componentDidMount","addTab","componentDidUpdate","activeTab","notifyUpdate","componentWillUnmount","removeTab","render","theme","renderMain","getIndicators","error","Boolean","warning","success","primary","children","Component","isActive","isVertical","vertical","orientationStyles","setRootNode","active","focus","__KONTUR_REACT_UI__","contextType","propTypes","node","bool","string","isRequired","func"],"mappings":"iPAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,SAAP,MAAsB,WAAtB;;AAEA,SAASC,cAAT,QAA+B,+BAA/B;AACA,SAASC,UAAT,EAAqBC,cAArB,EAAqCC,YAArC,QAAyD,uCAAzD;AACA,SAASC,WAAT,QAA4B,8BAA5B;;AAEA,SAASC,qBAAT,QAAsC,iBAAtC;AACA,SAASC,YAAT,QAA6B,gCAA7B;;AAEA,SAAsBC,aAAtB,QAA2C,8BAA3C;AACA,SAASC,EAAT,QAAmB,2BAAnB;AACA,SAASC,QAAT,QAAuC,oBAAvC;AACA,SAASC,iBAAT,QAAkC,6BAAlC;;AAEA,SAASC,WAAT,EAAuCC,uBAAvC,QAAsE,eAAtE;AACA,SAASC,MAAT,EAAiBC,gBAAjB,EAAmCC,cAAnC,EAAmDC,aAAnD,QAAwE,cAAxE;;;;;;;;;;AAUA,OAAO,IAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,WADmB,EAApB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AoD/E,KAAK,CAACwE,SAA1D,WACgBQ,mBADhB,GACsC,KADtC,UAGgBC,WAHhB,GAG8BnE,WAH9B,UAMgBoE,SANhB,GAM4B,EACxBX,QAAQ,EAAEtE,SAAS,CAACkF,IADI,EAExB5C,QAAQ,EAAEtC,SAAS,CAACmF,IAFI,EAGxBnD,IAAI,EAAEhC,SAAS,CAACoF,MAAV,CAAiBC,UAHC,EAIxB5C,OAAO,EAAEzC,SAAS,CAACsF,IAJK,EAKxBzC,SAAS,EAAE7C,SAAS,CAACsF,IALG,EAN5B,UAcgB7D,YAdhB,GAc6C,EACzCe,SAAS,EAAE,GAD8B,EAEzCR,IAAI,EAAE,EAFmC,EAd7C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport invariant from 'invariant';\n\nimport { ResizeDetector } from '../../internal/ResizeDetector';\nimport { isKeyArrow, isKeyArrowLeft, isKeyArrowUp } from '../../lib/events/keyboard/identifiers';\nimport { keyListener } from '../../lib/events/keyListener';\nimport { Nullable } from '../../typings/utility-types';\nimport { isFunctionalComponent } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { TabsContext, TabsContextType, TabsContextDefaultValue } from './TabsContext';\nimport { styles, horizontalStyles, verticalStyles, globalClasses } from './Tab.styles';\n\nexport interface TabIndicators {\n error: boolean;\n warning: boolean;\n success: boolean;\n primary: boolean;\n disabled: boolean;\n}\n\nexport const TabDataTids = {\n root: 'Tab__root',\n} as const;\n\nexport interface TabProps<T extends string = string> extends CommonProps {\n /**\n * Tab content\n */\n children?: React.ReactNode;\n\n /**\n * Component to use as a tab\n */\n component?: React.ComponentType<any> | string;\n\n /**\n * Link href\n */\n href?: string;\n\n /**\n * Tab identifier\n */\n id?: T;\n\n /**\n * Click event\n */\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n\n /**\n * Click event\n */\n onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;\n\n /**\n * Disabled indicator\n */\n disabled?: boolean;\n\n /**\n * Состояние валидации при ошибке.\n */\n error?: boolean;\n\n /**\n * Состояние валидации при предупреждении.\n */\n warning?: boolean;\n\n /**\n * Success indicator\n */\n success?: boolean;\n\n /**\n * Primary indicator\n */\n primary?: boolean;\n\n /**\n * Style property\n */\n style?: React.CSSProperties;\n}\n\nexport interface TabState {\n focusedByKeyboard: boolean;\n}\n\ntype DefaultProps = Required<Pick<TabProps, 'component' | 'href'>>;\n\n/**\n * Tab element of Tabs component\n *\n * Can be used for creating custom tabs\n * ```js\n *\n * const RouteTab = (props) => (\n * <Tab id={props.to} component={RouteLink} {...props}/>\n * )\n *\n * const MyAwesomeTab = (props) => <Tab id={props.id}>8) {props.children}</Tab>\n * ```\n *\n * Works only inside Tabs component, otherwise throws\n */\n@rootNode\nexport class Tab<T extends string = string> extends React.Component<TabProps<T>, TabState> {\n public static __KONTUR_REACT_UI__ = 'Tab';\n\n public static contextType = TabsContext;\n public context: TabsContextType = this.context;\n\n public static propTypes = {\n children: PropTypes.node,\n disabled: PropTypes.bool,\n href: PropTypes.string.isRequired,\n onClick: PropTypes.func,\n onKeyDown: PropTypes.func,\n };\n\n public static defaultProps: DefaultProps = {\n component: 'a',\n href: '',\n };\n\n private getProps = createPropsGetter(Tab.defaultProps);\n\n public state: TabState = {\n focusedByKeyboard: false,\n };\n\n private theme!: Theme;\n private tabComponent: Nullable<React.ReactElement<Tab<T>>> = null;\n private setRootNode!: TSetRootNode;\n\n constructor(props: TabProps<T>) {\n super(props);\n invariant(this.context !== TabsContextDefaultValue, 'Tab should be placed inside Tabs component');\n }\n\n public componentDidMount() {\n const id = this.getId();\n if (typeof id === 'string') {\n this.context.addTab(id, this.getTabInstance);\n }\n }\n\n public componentDidUpdate() {\n if (this.context.activeTab === this.props.id) {\n this.context.notifyUpdate();\n }\n }\n\n public componentWillUnmount() {\n const id = this.getId();\n if (typeof id === 'string') {\n this.context.removeTab(id);\n }\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n public getIndicators() {\n return {\n error: Boolean(this.props.error),\n warning: Boolean(this.props.warning),\n success: Boolean(this.props.success),\n primary: Boolean(this.props.primary),\n disabled: Boolean(this.props.disabled),\n };\n }\n\n public getUnderlyingNode = () => this.tabComponent;\n\n private renderMain() {\n const { children, disabled, error, warning, success, primary } = this.props;\n const { component: Component, href } = this.getProps();\n\n let isActive = false;\n let isVertical = false;\n\n const id = this.getId();\n if (typeof id === 'string') {\n isActive = this.context.activeTab === this.getId();\n isVertical = this.context.vertical;\n }\n const orientationStyles = isVertical ? verticalStyles : horizontalStyles;\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <Component\n data-tid={TabDataTids.root}\n className={cx({\n [styles.root(this.theme)]: true,\n [styles.vertical(this.theme)]: !!isVertical,\n [orientationStyles.primary(this.theme)]: !!primary,\n [orientationStyles.success(this.theme)]: !!success,\n [orientationStyles.warning(this.theme)]: !!warning,\n [orientationStyles.error(this.theme)]: !!error,\n [styles.active()]: !!isActive,\n [orientationStyles.active(this.theme)]: !!isActive,\n [styles.disabled(this.theme)]: !!disabled,\n [orientationStyles.disabled()]: !!disabled,\n })}\n onBlur={this.handleBlur}\n onClick={this.switchTab}\n onFocus={this.handleFocus}\n onKeyDown={this.handleKeyDown}\n tabIndex={disabled ? -1 : 0}\n ref={isFunctionalComponent(Component) ? null : this.refTabComponent}\n href={href}\n >\n <ResizeDetector onResize={this.context.notifyUpdate}>{children}</ResizeDetector>\n {this.state.focusedByKeyboard && <div className={cx(styles.focus(this.theme), globalClasses.focus)} />}\n </Component>\n </CommonWrapper>\n );\n }\n\n private getId = () => this.props.id || this.getProps().href;\n\n private refTabComponent = (instance: React.ReactElement<any>) => {\n this.tabComponent = instance;\n };\n\n private getTabInstance = () => this;\n\n private switchTab = (event: React.MouseEvent<HTMLElement>) => {\n if (this.props.disabled) {\n event.preventDefault();\n return;\n }\n const { href, component } = this.getProps();\n\n const id = this.props.id || href;\n if (this.props.onClick) {\n this.props.onClick(event);\n if (event.defaultPrevented) {\n return;\n }\n }\n if (typeof id === 'string') {\n this.context.switchTab(id);\n }\n if (component === 'a' && !href) {\n event.preventDefault();\n }\n };\n\n private handleKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {\n if (this.props.disabled) {\n return;\n }\n\n if (this.props.onKeyDown) {\n this.props.onKeyDown(e);\n if (e.defaultPrevented) {\n return;\n }\n }\n const id = this.getId();\n if (typeof id !== 'string') {\n return;\n }\n if (!isKeyArrow(e)) {\n return;\n }\n e.preventDefault();\n const delta = isKeyArrowLeft(e) || isKeyArrowUp(e) ? -1 : 1;\n this.context.shiftFocus(id, delta);\n };\n\n private handleFocus = () => {\n if (this.props.disabled) {\n return;\n }\n\n // focus event fires before keyDown eventlistener\n // so we should check focusKeyPressed in async way\n requestAnimationFrame(() => {\n if (keyListener.isTabPressed || keyListener.isArrowPressed) {\n this.setState({ focusedByKeyboard: true });\n }\n });\n };\n\n private handleBlur = () => {\n if (this.props.disabled) {\n return;\n }\n\n this.setState({ focusedByKeyboard: false });\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["Tab.tsx"],"names":["React","invariant","ResizeDetector","isKeyArrow","isKeyArrowLeft","isKeyArrowUp","keyListener","isFunctionalComponent","ThemeContext","CommonWrapper","cx","rootNode","createPropsGetter","TabsContext","TabsContextDefaultValue","styles","horizontalStyles","verticalStyles","globalClasses","TabDataTids","root","Tab","props","context","getProps","defaultProps","state","focusedByKeyboard","tabComponent","getUnderlyingNode","getId","id","href","refTabComponent","instance","getTabInstance","switchTab","event","disabled","preventDefault","component","onClick","defaultPrevented","handleKeyDown","e","onKeyDown","delta","shiftFocus","handleFocus","requestAnimationFrame","isTabPressed","isArrowPressed","setState","handleBlur","componentDidMount","addTab","componentDidUpdate","activeTab","notifyUpdate","componentWillUnmount","removeTab","render","theme","renderMain","getIndicators","error","Boolean","warning","success","primary","children","Component","isActive","isVertical","vertical","orientationStyles","setRootNode","active","focus","__KONTUR_REACT_UI__","contextType"],"mappings":"iPAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,WAAtB;;AAEA,SAASC,cAAT,QAA+B,+BAA/B;AACA,SAASC,UAAT,EAAqBC,cAArB,EAAqCC,YAArC,QAAyD,uCAAzD;AACA,SAASC,WAAT,QAA4B,8BAA5B;;AAEA,SAASC,qBAAT,QAAsC,iBAAtC;AACA,SAASC,YAAT,QAA6B,gCAA7B;;AAEA,SAAsBC,aAAtB,QAA2C,8BAA3C;AACA,SAASC,EAAT,QAAmB,2BAAnB;AACA,SAASC,QAAT,QAAuC,oBAAvC;AACA,SAASC,iBAAT,QAAkC,6BAAlC;;AAEA,SAASC,WAAT,EAAuCC,uBAAvC,QAAsE,eAAtE;AACA,SAASC,MAAT,EAAiBC,gBAAjB,EAAmCC,cAAnC,EAAmDC,aAAnD,QAAwE,cAAxE;;;;;;;;;;AAUA,OAAO,IAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,WADmB,EAApB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwFP,OAhBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAEA,IAAaC,GAAb,GADCV,QACD;;;;;;;AAqBE,eAAYW,KAAZ,EAAgC;AAC9B,wCAAMA,KAAN,UAD8B,MAjBzBC,OAiByB,GAjBE,MAAKA,OAiBP,OAVxBC,QAUwB,GAVbZ,iBAAiB,CAACS,GAAG,CAACI,YAAL,CAUJ,OARzBC,KAQyB,G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,MAAP,EAPU,IAOQ,CAAC,CAACL,QAPV,MAQVG,iBAAiB,CAACE,MAAlB,CAAyB,KAAKf,KAA9B,CARU,IAQ6B,CAAC,CAACU,QAR/B,MASVzD,MAAM,CAACuB,QAAP,CAAgB,KAAKwB,KAArB,CATU,IASoB,CAAC,CAACxB,QATtB,MAUVqC,iBAAiB,CAACrC,QAAlB,EAVU,IAUqB,CAAC,CAACA,QAVvB,OAFf,EAcE,MAAM,EAAE,KAAKe,UAdf,EAeE,OAAO,EAAE,KAAKjB,SAfhB,EAgBE,OAAO,EAAE,KAAKY,WAhBhB,EAiBE,SAAS,EAAE,KAAKL,aAjBlB,EAkBE,QAAQ,EAAEL,QAAQ,GAAG,CAAC,CAAJ,GAAQ,CAlB5B,EAmBE,GAAG,EAAE/B,qBAAqB,CAACgE,SAAD,CAArB,GAAmC,IAAnC,GAA0C,KAAKtC,eAnBtD,EAoBE,IAAI,EAAED,IApBR,iBAsBE,oBAAC,cAAD,IAAgB,QAAQ,EAAE,KAAKT,OAAL,CAAamC,YAAvC,IAAsDY,QAAtD,CAtBF,EAuBG,KAAK5C,KAAL,CAAWC,iBAAX,iBAAgC,6BAAK,SAAS,EAAEjB,EAAE,CAACK,MAAM,CAAC+D,KAAP,CAAa,KAAKhB,KAAlB,CAAD,EAA2B5C,aAAa,CAAC4D,KAAzC,CAAlB,GAvBnC,CADF,CADF,CA6BD,CAhHH,cAAoD9E,KAAK,CAACuE,SAA1D,WACgBQ,mBADhB,GACsC,KADtC,UAGgBC,WAHhB,GAG8BnE,WAH9B,UAMgBY,YANhB,GAM6C,EACzCe,SAAS,EAAE,GAD8B,EAEzCR,IAAI,EAAE,EAFmC,EAN7C","sourcesContent":["import React from 'react';\nimport invariant from 'invariant';\n\nimport { ResizeDetector } from '../../internal/ResizeDetector';\nimport { isKeyArrow, isKeyArrowLeft, isKeyArrowUp } from '../../lib/events/keyboard/identifiers';\nimport { keyListener } from '../../lib/events/keyListener';\nimport { Nullable } from '../../typings/utility-types';\nimport { isFunctionalComponent } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { TabsContext, TabsContextType, TabsContextDefaultValue } from './TabsContext';\nimport { styles, horizontalStyles, verticalStyles, globalClasses } from './Tab.styles';\n\nexport interface TabIndicators {\n error: boolean;\n warning: boolean;\n success: boolean;\n primary: boolean;\n disabled: boolean;\n}\n\nexport const TabDataTids = {\n root: 'Tab__root',\n} as const;\n\nexport interface TabProps<T extends string = string> extends CommonProps {\n /**\n * Tab content\n */\n children?: React.ReactNode;\n\n /**\n * Component to use as a tab\n */\n component?: React.ComponentType<any> | string;\n\n /**\n * Link href\n */\n href?: string;\n\n /**\n * Tab identifier\n */\n id?: T;\n\n /**\n * Click event\n */\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n\n /**\n * Click event\n */\n onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;\n\n /**\n * Disabled indicator\n */\n disabled?: boolean;\n\n /**\n * Состояние валидации при ошибке.\n */\n error?: boolean;\n\n /**\n * Состояние валидации при предупреждении.\n */\n warning?: boolean;\n\n /**\n * Success indicator\n */\n success?: boolean;\n\n /**\n * Primary indicator\n */\n primary?: boolean;\n\n /**\n * Style property\n */\n style?: React.CSSProperties;\n}\n\nexport interface TabState {\n focusedByKeyboard: boolean;\n}\n\ntype DefaultProps = Required<Pick<TabProps, 'component' | 'href'>>;\n\n/**\n * Tab element of Tabs component\n *\n * Can be used for creating custom tabs\n * ```js\n *\n * const RouteTab = (props) => (\n * <Tab id={props.to} component={RouteLink} {...props}/>\n * )\n *\n * const MyAwesomeTab = (props) => <Tab id={props.id}>8) {props.children}</Tab>\n * ```\n *\n * Works only inside Tabs component, otherwise throws\n */\n@rootNode\nexport class Tab<T extends string = string> extends React.Component<TabProps<T>, TabState> {\n public static __KONTUR_REACT_UI__ = 'Tab';\n\n public static contextType = TabsContext;\n public context: TabsContextType = this.context;\n\n public static defaultProps: DefaultProps = {\n component: 'a',\n href: '',\n };\n\n private getProps = createPropsGetter(Tab.defaultProps);\n\n public state: TabState = {\n focusedByKeyboard: false,\n };\n\n private theme!: Theme;\n private tabComponent: Nullable<React.ReactElement<Tab<T>>> = null;\n private setRootNode!: TSetRootNode;\n\n constructor(props: TabProps<T>) {\n super(props);\n invariant(this.context !== TabsContextDefaultValue, 'Tab should be placed inside Tabs component');\n }\n\n public componentDidMount() {\n const id = this.getId();\n if (typeof id === 'string') {\n this.context.addTab(id, this.getTabInstance);\n }\n }\n\n public componentDidUpdate() {\n if (this.context.activeTab === this.props.id) {\n this.context.notifyUpdate();\n }\n }\n\n public componentWillUnmount() {\n const id = this.getId();\n if (typeof id === 'string') {\n this.context.removeTab(id);\n }\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n public getIndicators() {\n return {\n error: Boolean(this.props.error),\n warning: Boolean(this.props.warning),\n success: Boolean(this.props.success),\n primary: Boolean(this.props.primary),\n disabled: Boolean(this.props.disabled),\n };\n }\n\n public getUnderlyingNode = () => this.tabComponent;\n\n private renderMain() {\n const { children, disabled, error, warning, success, primary } = this.props;\n const { component: Component, href } = this.getProps();\n\n let isActive = false;\n let isVertical = false;\n\n const id = this.getId();\n if (typeof id === 'string') {\n isActive = this.context.activeTab === this.getId();\n isVertical = this.context.vertical;\n }\n const orientationStyles = isVertical ? verticalStyles : horizontalStyles;\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <Component\n data-tid={TabDataTids.root}\n className={cx({\n [styles.root(this.theme)]: true,\n [styles.vertical(this.theme)]: !!isVertical,\n [orientationStyles.primary(this.theme)]: !!primary,\n [orientationStyles.success(this.theme)]: !!success,\n [orientationStyles.warning(this.theme)]: !!warning,\n [orientationStyles.error(this.theme)]: !!error,\n [styles.active()]: !!isActive,\n [orientationStyles.active(this.theme)]: !!isActive,\n [styles.disabled(this.theme)]: !!disabled,\n [orientationStyles.disabled()]: !!disabled,\n })}\n onBlur={this.handleBlur}\n onClick={this.switchTab}\n onFocus={this.handleFocus}\n onKeyDown={this.handleKeyDown}\n tabIndex={disabled ? -1 : 0}\n ref={isFunctionalComponent(Component) ? null : this.refTabComponent}\n href={href}\n >\n <ResizeDetector onResize={this.context.notifyUpdate}>{children}</ResizeDetector>\n {this.state.focusedByKeyboard && <div className={cx(styles.focus(this.theme), globalClasses.focus)} />}\n </Component>\n </CommonWrapper>\n );\n }\n\n private getId = () => this.props.id || this.getProps().href;\n\n private refTabComponent = (instance: React.ReactElement<any>) => {\n this.tabComponent = instance;\n };\n\n private getTabInstance = () => this;\n\n private switchTab = (event: React.MouseEvent<HTMLElement>) => {\n if (this.props.disabled) {\n event.preventDefault();\n return;\n }\n const { href, component } = this.getProps();\n\n const id = this.props.id || href;\n if (this.props.onClick) {\n this.props.onClick(event);\n if (event.defaultPrevented) {\n return;\n }\n }\n if (typeof id === 'string') {\n this.context.switchTab(id);\n }\n if (component === 'a' && !href) {\n event.preventDefault();\n }\n };\n\n private handleKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {\n if (this.props.disabled) {\n return;\n }\n\n if (this.props.onKeyDown) {\n this.props.onKeyDown(e);\n if (e.defaultPrevented) {\n return;\n }\n }\n const id = this.getId();\n if (typeof id !== 'string') {\n return;\n }\n if (!isKeyArrow(e)) {\n return;\n }\n e.preventDefault();\n const delta = isKeyArrowLeft(e) || isKeyArrowUp(e) ? -1 : 1;\n this.context.shiftFocus(id, delta);\n };\n\n private handleFocus = () => {\n if (this.props.disabled) {\n return;\n }\n\n // focus event fires before keyDown eventlistener\n // so we should check focusKeyPressed in async way\n requestAnimationFrame(() => {\n if (keyListener.isTabPressed || keyListener.isArrowPressed) {\n this.setState({ focusedByKeyboard: true });\n }\n });\n };\n\n private handleBlur = () => {\n if (this.props.disabled) {\n return;\n }\n\n this.setState({ focusedByKeyboard: false });\n };\n}\n"]}
|
package/components/Tabs/Tab.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { Nullable } from '../../typings/utility-types';
|
|
4
3
|
import { CommonProps } from '../../internal/CommonWrapper';
|
|
5
4
|
import { TabsContextType } from './TabsContext';
|
|
@@ -86,13 +85,6 @@ export declare class Tab<T extends string = string> extends React.Component<TabP
|
|
|
86
85
|
static __KONTUR_REACT_UI__: string;
|
|
87
86
|
static contextType: React.Context<TabsContextType<any>>;
|
|
88
87
|
context: TabsContextType;
|
|
89
|
-
static propTypes: {
|
|
90
|
-
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
91
|
-
disabled: PropTypes.Requireable<boolean>;
|
|
92
|
-
href: PropTypes.Validator<string>;
|
|
93
|
-
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
94
|
-
onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
95
|
-
};
|
|
96
88
|
static defaultProps: DefaultProps;
|
|
97
89
|
private getProps;
|
|
98
90
|
state: TabState;
|
|
@@ -5,7 +5,6 @@ import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
|
5
5
|
var _class, _class2, _temp;
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
8
|
import { ThemeContext } from "../../../lib/theming/ThemeContext";
|
|
10
9
|
import { CommonWrapper } from "../../../internal/CommonWrapper";
|
|
11
10
|
import { cx } from "../../../lib/theming/Emotion";
|
|
@@ -150,12 +149,6 @@ var Tabs = rootNode(_class = (_temp = _class2 = /*#__PURE__*/function (_React$Co
|
|
|
150
149
|
};
|
|
151
150
|
|
|
152
151
|
return Tabs;
|
|
153
|
-
}(React.Component), _class2.__KONTUR_REACT_UI__ = 'Tabs', _class2.
|
|
154
|
-
children: PropTypes.node,
|
|
155
|
-
indicatorClassName: PropTypes.string,
|
|
156
|
-
value: PropTypes.string.isRequired,
|
|
157
|
-
vertical: PropTypes.bool,
|
|
158
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
159
|
-
}, _class2.defaultProps = {
|
|
152
|
+
}(React.Component), _class2.__KONTUR_REACT_UI__ = 'Tabs', _class2.defaultProps = {
|
|
160
153
|
vertical: false
|
|
161
154
|
}, _class2.Tab = Tab, _temp)) || _class;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Tabs.tsx"],"names":["React","
|
|
1
|
+
{"version":3,"sources":["Tabs.tsx"],"names":["React","ThemeContext","CommonWrapper","cx","getRootNode","rootNode","createPropsGetter","Indicator","styles","TabsContext","Tab","TabsDataTids","root","indicatorRoot","Tabs","getProps","defaultProps","tabs","tabUpdates","on","cb","index","listeners","push","splice","shiftFocus","fromTab","delta","findIndex","x","id","newIndex","Math","max","min","length","tab","tabNode","getNode","htmlNode","HTMLElement","focus","notifyUpdate","forEach","switchTab","props","onValueChange","value","getTab","find","addTab","concat","removeTab","filter","render","width","children","indicatorClassName","vertical","theme","setRootNode","activeTab","Component","__KONTUR_REACT_UI__"],"mappings":"iPAAA,OAAOA,KAAP,MAAkB,OAAlB;;;AAGA,SAASC,YAAT,QAA6B,gCAA7B;;AAEA,SAAsBC,aAAtB,QAA2C,8BAA3C;AACA,SAASC,EAAT,QAAmB,2BAAnB;AACA,SAASC,WAAT,QAA4B,gCAA5B;AACA,SAASC,QAAT,QAAuC,oBAAvC;AACA,SAASC,iBAAT,QAAkC,6BAAlC;;AAEA,SAASC,SAAT,QAA0B,aAA1B;AACA,SAASC,MAAT,QAAuB,eAAvB;AACA,SAASC,WAAT,QAA6C,eAA7C;AACA,SAASC,GAAT,QAAoB,OAApB;;;;;;;;;;;;;;;;;;;;;;;;;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E,KAD+B,EAH7C,UASgBhD,GAThB,GASsBA,GATtB","sourcesContent":["import React from 'react';\n\nimport { emptyHandler } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { getRootNode } from '../../lib/rootNode/getRootNode';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { Indicator } from './Indicator';\nimport { styles } from './Tabs.styles';\nimport { TabsContext, TabsContextType } from './TabsContext';\nimport { Tab } from './Tab';\n\ntype ValueBaseType = string;\ninterface TabType<T extends ValueBaseType> {\n getNode: () => Tab<T> | null;\n id: T;\n}\n\nexport interface TabsProps<T extends ValueBaseType = string> extends CommonProps {\n /**\n * Tab component should be child of Tabs component\n */\n children?: React.ReactNode;\n\n /**\n * Classname of indicator\n */\n indicatorClassName?: string;\n\n /**\n * Tabs change event\n */\n onValueChange?: (value: T) => void;\n\n /**\n * Active tab identifier\n */\n value: T;\n\n /**\n * Vertical indicator\n * @default false\n */\n vertical?: boolean;\n\n /**\n * Width of tabs container\n */\n width?: number | string;\n}\n\nexport const TabsDataTids = {\n root: 'Tabs__root',\n indicatorRoot: 'Indicator__root',\n} as const;\n\ntype DefaultProps = Required<Pick<TabsProps, 'vertical'>>;\n\n/**\n * Tabs wrapper\n *\n * contains static property `Tab`\n */\n@rootNode\nexport class Tabs<T extends string = string> extends React.Component<TabsProps<T>> {\n public static __KONTUR_REACT_UI__ = 'Tabs';\n\n public static defaultProps: DefaultProps = {\n vertical: false,\n };\n\n private getProps = createPropsGetter(Tabs.defaultProps);\n\n public static Tab = Tab;\n\n private theme!: Theme;\n\n private tabs: Array<TabType<T>> = [];\n\n private tabUpdates = {\n on: (cb: () => void) => {\n const index = this.listeners.push(cb);\n return () => {\n this.listeners.splice(index, 1);\n };\n },\n };\n\n private listeners: Array<typeof emptyHandler> = [];\n private setRootNode!: TSetRootNode;\n\n public render(): JSX.Element {\n const { value, width, children, indicatorClassName } = this.props;\n const vertical = this.getProps().vertical;\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div\n data-tid={TabsDataTids.root}\n className={cx(styles.root(this.theme), vertical && styles.vertical())}\n style={{ width }}\n >\n <TabsContext.Provider\n value={{\n vertical,\n activeTab: value,\n getTab: this.getTab,\n addTab: this.addTab,\n removeTab: this.removeTab,\n notifyUpdate: this.notifyUpdate,\n shiftFocus: this.shiftFocus,\n switchTab: this.switchTab,\n }}\n >\n {children}\n <Indicator\n className={indicatorClassName}\n tabUpdates={this.tabUpdates}\n vertical={this.getProps().vertical}\n />\n </TabsContext.Provider>\n </div>\n </CommonWrapper>\n );\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private shiftFocus: TabsContextType<T>['shiftFocus'] = (fromTab, delta) => {\n const { tabs } = this;\n const index = tabs.findIndex((x) => x.id === fromTab);\n const newIndex = Math.max(0, Math.min(index + delta, tabs.length - 1));\n const tab = tabs[newIndex];\n\n const tabNode = tab.getNode();\n const htmlNode = getRootNode(tabNode);\n\n if (htmlNode && htmlNode instanceof HTMLElement && typeof htmlNode.focus === 'function') {\n htmlNode.focus();\n }\n };\n\n private notifyUpdate: TabsContextType<T>['notifyUpdate'] = () => {\n this.listeners.forEach((cb) => cb());\n };\n\n private switchTab: TabsContextType<T>['switchTab'] = (id) => {\n const { onValueChange, value } = this.props;\n if (id !== value && onValueChange) {\n onValueChange(id);\n }\n };\n\n private getTab: TabsContextType<T>['getTab'] = (id) => {\n const { getNode = null } = this.tabs.find((x) => x.id === id) || {};\n return getNode && getNode();\n };\n\n private addTab: TabsContextType<T>['addTab'] = (id, getNode) => {\n this.tabs = this.tabs.concat({ id, getNode });\n };\n\n private removeTab: TabsContextType<T>['removeTab'] = (id) => {\n this.tabs = this.tabs.filter((tab) => tab.id !== id);\n };\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { CommonProps } from '../../internal/CommonWrapper';
|
|
4
3
|
import { Tab } from './Tab';
|
|
5
4
|
declare type ValueBaseType = string;
|
|
@@ -42,13 +41,6 @@ declare type DefaultProps = Required<Pick<TabsProps, 'vertical'>>;
|
|
|
42
41
|
*/
|
|
43
42
|
export declare class Tabs<T extends string = string> extends React.Component<TabsProps<T>> {
|
|
44
43
|
static __KONTUR_REACT_UI__: string;
|
|
45
|
-
static propTypes: {
|
|
46
|
-
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
47
|
-
indicatorClassName: PropTypes.Requireable<string>;
|
|
48
|
-
value: PropTypes.Validator<string>;
|
|
49
|
-
vertical: PropTypes.Requireable<boolean>;
|
|
50
|
-
width: PropTypes.Requireable<string | number>;
|
|
51
|
-
};
|
|
52
44
|
static defaultProps: DefaultProps;
|
|
53
45
|
private getProps;
|
|
54
46
|
static Tab: typeof Tab;
|
package/index.d.ts
CHANGED
|
@@ -52,3 +52,5 @@ export * from './lib/theming/themes/FlatTheme8pxOld';
|
|
|
52
52
|
export * from './lib/theming/themes/Theme2022';
|
|
53
53
|
export * from './lib/theming/themes/Theme2022Dark';
|
|
54
54
|
export * from './internal/Popup/types';
|
|
55
|
+
export * as ColorFunctions from './lib/styles/ColorFunctions';
|
|
56
|
+
export * as DimensionFunctions from './lib/styles/DimensionFunctions';
|
package/index.js
CHANGED
|
@@ -51,4 +51,6 @@ export * from './lib/theming/themes/DefaultTheme8pxOld';
|
|
|
51
51
|
export * from './lib/theming/themes/FlatTheme8pxOld';
|
|
52
52
|
export * from './lib/theming/themes/Theme2022';
|
|
53
53
|
export * from './lib/theming/themes/Theme2022Dark';
|
|
54
|
-
export * from './internal/Popup/types';
|
|
54
|
+
export * from './internal/Popup/types';import * as _ColorFunctions from
|
|
55
|
+
'./lib/styles/ColorFunctions';export { _ColorFunctions as ColorFunctions };import * as _DimensionFunctions from
|
|
56
|
+
'./lib/styles/DimensionFunctions';export { _DimensionFunctions as DimensionFunctions };
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAAd;AACA,cAAc,qBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,uBAAd;AACA,cAAc,4BAAd;AACA,cAAc,4BAAd;AACA,cAAc,wBAAd;AACA,cAAc,yBAAd;AACA,cAAc,uBAAd;AACA,cAAc,2BAAd;AACA,cAAc,2BAAd;AACA,cAAc,sBAAd;AACA,cAAc,qBAAd;AACA,cAAc,2BAAd;AACA,cAAc,oBAAd;AACA,cAAc,mBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,mBAAd;AACA,cAAc,qBAAd;AACA,cAAc,yBAAd;AACA,cAAc,uBAAd;AACA,cAAc,4BAAd;AACA,cAAc,oBAAd;AACA,cAAc,qBAAd;AACA,cAAc,4BAAd;AACA,cAAc,oBAAd;AACA,cAAc,yBAAd;AACA,cAAc,8BAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,sBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,mBAAd;AACA,cAAc,uBAAd;AACA,cAAc,oBAAd;AACA,cAAc,qBAAd;AACA,cAAc,oBAAd;AACA,cAAc,yBAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,+BAAd;AACA,cAAc,cAAd;AACA,cAAc,4BAAd;AACA,cAAc,4BAAd;AACA,cAAc,mCAAd;AACA,cAAc,gCAAd;AACA,cAAc,yCAAd;AACA,cAAc,sCAAd;AACA,cAAc,gCAAd;AACA,cAAc,oCAAd;AACA,cAAc,wBAAd","sourcesContent":["export * from './components/Autocomplete';\nexport * from './components/Button';\nexport * from './components/Center';\nexport * from './components/Checkbox';\nexport * from './components/ComboBox';\nexport * from './components/CurrencyInput';\nexport * from './components/CurrencyLabel';\nexport * from './components/DateInput';\nexport * from './components/DatePicker';\nexport * from './components/Dropdown';\nexport * from './components/DropdownMenu';\nexport * from './components/FileUploader';\nexport * from './components/FxInput';\nexport * from './components/Gapped';\nexport * from './components/GlobalLoader';\nexport * from './components/Group';\nexport * from './components/Hint';\nexport * from './components/Input';\nexport * from './components/Kebab';\nexport * from './components/Link';\nexport * from './components/Loader';\nexport * from './components/MenuHeader';\nexport * from './components/MenuItem';\nexport * from './components/MenuSeparator';\nexport * from './components/Modal';\nexport * from './components/Paging';\nexport * from './components/PasswordInput';\nexport * from './components/Radio';\nexport * from './components/RadioGroup';\nexport * from './components/ScrollContainer';\nexport * from './components/Select';\nexport * from './components/SidePage';\nexport * from './components/Spinner';\nexport * from './components/Sticky';\nexport * from './components/Switcher';\nexport * from './components/Tabs';\nexport * from './components/Textarea';\nexport * from './components/Toast';\nexport * from './components/Toggle';\nexport * from './components/Token';\nexport * from './components/TokenInput';\nexport * from './components/Tooltip';\nexport * from './components/TooltipMenu';\nexport * from './components/ResponsiveLayout';\nexport * from './lib/locale';\nexport * from './lib/theming/ThemeContext';\nexport * from './lib/theming/ThemeFactory';\nexport * from './lib/theming/themes/DefaultTheme';\nexport * from './lib/theming/themes/DarkTheme';\nexport * from './lib/theming/themes/DefaultTheme8pxOld';\nexport * from './lib/theming/themes/FlatTheme8pxOld';\nexport * from './lib/theming/themes/Theme2022';\nexport * from './lib/theming/themes/Theme2022Dark';\nexport * from './internal/Popup/types';\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["ColorFunctions","DimensionFunctions"],"mappings":"AAAA,cAAc,2BAAd;AACA,cAAc,qBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,uBAAd;AACA,cAAc,4BAAd;AACA,cAAc,4BAAd;AACA,cAAc,wBAAd;AACA,cAAc,yBAAd;AACA,cAAc,uBAAd;AACA,cAAc,2BAAd;AACA,cAAc,2BAAd;AACA,cAAc,sBAAd;AACA,cAAc,qBAAd;AACA,cAAc,2BAAd;AACA,cAAc,oBAAd;AACA,cAAc,mBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,mBAAd;AACA,cAAc,qBAAd;AACA,cAAc,yBAAd;AACA,cAAc,uBAAd;AACA,cAAc,4BAAd;AACA,cAAc,oBAAd;AACA,cAAc,qBAAd;AACA,cAAc,4BAAd;AACA,cAAc,oBAAd;AACA,cAAc,yBAAd;AACA,cAAc,8BAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,sBAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,mBAAd;AACA,cAAc,uBAAd;AACA,cAAc,oBAAd;AACA,cAAc,qBAAd;AACA,cAAc,oBAAd;AACA,cAAc,yBAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,+BAAd;AACA,cAAc,cAAd;AACA,cAAc,4BAAd;AACA,cAAc,4BAAd;AACA,cAAc,mCAAd;AACA,cAAc,gCAAd;AACA,cAAc,yCAAd;AACA,cAAc,sCAAd;AACA,cAAc,gCAAd;AACA,cAAc,oCAAd;AACA,cAAc,wBAAd,C;AACgC,6B,6BAApBA,c;AACwB,iC,iCAAxBC,kB","sourcesContent":["export * from './components/Autocomplete';\nexport * from './components/Button';\nexport * from './components/Center';\nexport * from './components/Checkbox';\nexport * from './components/ComboBox';\nexport * from './components/CurrencyInput';\nexport * from './components/CurrencyLabel';\nexport * from './components/DateInput';\nexport * from './components/DatePicker';\nexport * from './components/Dropdown';\nexport * from './components/DropdownMenu';\nexport * from './components/FileUploader';\nexport * from './components/FxInput';\nexport * from './components/Gapped';\nexport * from './components/GlobalLoader';\nexport * from './components/Group';\nexport * from './components/Hint';\nexport * from './components/Input';\nexport * from './components/Kebab';\nexport * from './components/Link';\nexport * from './components/Loader';\nexport * from './components/MenuHeader';\nexport * from './components/MenuItem';\nexport * from './components/MenuSeparator';\nexport * from './components/Modal';\nexport * from './components/Paging';\nexport * from './components/PasswordInput';\nexport * from './components/Radio';\nexport * from './components/RadioGroup';\nexport * from './components/ScrollContainer';\nexport * from './components/Select';\nexport * from './components/SidePage';\nexport * from './components/Spinner';\nexport * from './components/Sticky';\nexport * from './components/Switcher';\nexport * from './components/Tabs';\nexport * from './components/Textarea';\nexport * from './components/Toast';\nexport * from './components/Toggle';\nexport * from './components/Token';\nexport * from './components/TokenInput';\nexport * from './components/Tooltip';\nexport * from './components/TooltipMenu';\nexport * from './components/ResponsiveLayout';\nexport * from './lib/locale';\nexport * from './lib/theming/ThemeContext';\nexport * from './lib/theming/ThemeFactory';\nexport * from './lib/theming/themes/DefaultTheme';\nexport * from './lib/theming/themes/DarkTheme';\nexport * from './lib/theming/themes/DefaultTheme8pxOld';\nexport * from './lib/theming/themes/FlatTheme8pxOld';\nexport * from './lib/theming/themes/Theme2022';\nexport * from './lib/theming/themes/Theme2022Dark';\nexport * from './internal/Popup/types';\nexport * as ColorFunctions from './lib/styles/ColorFunctions';\nexport * as DimensionFunctions from './lib/styles/DimensionFunctions';\n"]}
|