@semcore/tab-line 16.1.0-prerelease.1 → 16.1.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/lib/cjs/TabLine.js +76 -45
- package/lib/cjs/TabLine.js.map +1 -1
- package/lib/cjs/TabLine.type.js +2 -0
- package/lib/cjs/TabLine.type.js.map +1 -0
- package/lib/cjs/index.js +13 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/tab-line.shadow.css +2 -19
- package/lib/es6/TabLine.js +70 -39
- package/lib/es6/TabLine.js.map +1 -1
- package/lib/es6/TabLine.type.js +2 -0
- package/lib/es6/TabLine.type.js.map +1 -0
- package/lib/es6/index.js +2 -2
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/tab-line.shadow.css +2 -19
- package/lib/esm/TabLine.mjs +65 -41
- package/lib/esm/TabLine.type.mjs +1 -0
- package/lib/esm/index.mjs +1 -0
- package/lib/esm/style/tab-line.shadow.css +2 -19
- package/lib/types/TabLine.d.ts +6 -0
- package/lib/types/TabLine.type.d.ts +80 -0
- package/lib/types/index.d.ts +2 -102
- package/package.json +5 -5
- package/lib/cjs/index.d.js +0 -2
- package/lib/cjs/index.d.js.map +0 -1
- package/lib/es6/index.d.js +0 -2
- package/lib/es6/index.d.js.map +0 -1
package/lib/es6/TabLine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabLine.js","names":["createComponent","Component","sstyled","Root","addonTextChildren","a11yEnhance","Box","NeighborLocation","React","style","_sstyled","insert","optionsA11yEnhance","onNeighborChange","neighborElement","props","focus","behavior","click","childSelector","TabLineRoot","_Component","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","concat","_defineProperty","animation","undefined","createRef","_this$state$animation","state","started","setState","_objectSpread","value","e","handlers","_inherits","_createClass","key","uncontrolledProps","componentDidUpdate","prevValue","asProps","animate","componentDidMount","componentWillUnmount","clearTimeout","animationStartTimeout","fromNode","itemRefs","toNode","containerNode","containerRef","current","containerRect","getBoundingClientRect","fromRect","toRect","fromLeft","x","fromWidth","width","toLeft","toWidth","setTimeout","handleAnimationStart","getItemProps","_index","_this2","_this$asProps","size","isSelected","bindHandlerClick","ref","node","getCaretProps","left","onTransitionEnd","handleAnimationEnd","render","_ref","_ref5","STabLine","SCaret","_this$asProps2","styles","Children","controlsLength","createElement","cn","_assignProps","defaultValue","underlined","TabLineItem","_ref2","arguments[0]","STabLineItem","addonLeft","addonRight","neighborLocation","Detect","_ref6","_assignProps2","TabLine","Item","Addon","tag","Text","_ref3","_ref7","SText","_assignProps3","_ref4","_ref8","SAddon","_assignProps4","wrapTabLine","wrapper"],"sources":["../../src/TabLine.jsx"],"sourcesContent":["import { createComponent, Component, sstyled, Root } from '@semcore/core';\nimport addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';\nimport a11yEnhance from '@semcore/core/lib/utils/enhances/a11yEnhance';\nimport { Box } from '@semcore/flex-box';\nimport NeighborLocation from '@semcore/neighbor-location';\nimport React from 'react';\n\nimport style from './style/tab-line.shadow.css';\n\nconst optionsA11yEnhance = {\n onNeighborChange: (neighborElement, props) => {\n if (neighborElement) {\n neighborElement.focus();\n if (props.behavior === 'auto') {\n neighborElement.click();\n }\n }\n },\n childSelector: ['role', 'tab'],\n};\n\nclass TabLineRoot extends Component {\n static displayName = 'TabLine';\n static style = style;\n static defaultProps = {\n defaultValue: null,\n size: 'm',\n underlined: true,\n behavior: 'auto',\n };\n\n static enhance = [a11yEnhance(optionsA11yEnhance)];\n state = { animation: null };\n prevValue = undefined;\n itemRefs = {};\n containerRef = React.createRef();\n animationStartTimeout = -1;\n\n uncontrolledProps() {\n return {\n value: null,\n };\n }\n\n componentDidUpdate() {\n if (\n this.prevValue !== null &&\n this.asProps.value !== null &&\n this.prevValue !== this.asProps.value\n ) {\n this.animate();\n }\n this.prevValue = this.asProps.value;\n }\n\n componentDidMount() {\n this.prevValue = this.asProps.value;\n }\n\n componentWillUnmount() {\n clearTimeout(this.animationStartTimeout);\n }\n\n animate() {\n const fromNode = this.itemRefs[this.prevValue];\n const toNode = this.itemRefs[this.asProps.value];\n const containerNode = this.containerRef.current;\n\n if (!fromNode || !toNode || !containerNode) return;\n const containerRect = containerNode.getBoundingClientRect();\n const fromRect = fromNode.getBoundingClientRect();\n const toRect = toNode.getBoundingClientRect();\n const animation = {\n fromLeft: fromRect.x - containerRect.x,\n fromWidth: fromRect.width,\n toLeft: toRect.x - containerRect.x,\n toWidth: toRect.width,\n started: false,\n };\n this.setState({ animation });\n clearTimeout(this.animationStartTimeout);\n this.animationStartTimeout = setTimeout(this.handleAnimationStart, 0);\n }\n\n handleAnimationStart = () => {\n if (this.state.animation?.started === false) {\n this.setState({ animation: { ...this.state.animation, started: true } });\n }\n };\n\n handleAnimationEnd = () => {\n this.setState({ animation: null });\n };\n\n bindHandlerClick = (value) => (e) => {\n this.handlers.value(value, e);\n };\n\n getItemProps(props, _index) {\n const { value, size } = this.asProps;\n const isSelected = value === props.value;\n return {\n size,\n 'selected': isSelected,\n 'onClick': this.bindHandlerClick(props.value),\n 'tabIndex': isSelected ? 0 : -1,\n 'aria-selected': isSelected,\n 'ref': (node) => {\n this.itemRefs[props.value] = node;\n },\n };\n }\n\n getCaretProps() {\n const { animation } = this.state;\n if (!animation) return {};\n if (animation.started) {\n return {\n style: {\n left: animation.toLeft,\n width: animation.toWidth,\n },\n onTransitionEnd: this.handleAnimationEnd,\n };\n } else {\n return {\n style: {\n left: animation.fromLeft,\n width: animation.fromWidth,\n },\n onTransitionEnd: this.handleAnimationEnd,\n };\n }\n }\n\n render() {\n const STabLine = Root;\n const SCaret = Box;\n const { styles, Children, controlsLength } = this.asProps;\n const { animation } = this.state;\n\n return sstyled(styles)(\n <STabLine render={Box} role='tablist' ref={this.containerRef}>\n <NeighborLocation controlsLength={controlsLength}>\n <Children />\n </NeighborLocation>\n {animation && <SCaret {...this.getCaretProps()} />}\n </STabLine>,\n );\n }\n}\n\nfunction TabLineItem(props) {\n const STabLineItem = Root;\n const { Children, styles, addonLeft, addonRight, neighborLocation } = props;\n\n return (\n <NeighborLocation.Detect neighborLocation={neighborLocation}>\n {(neighborLocation) =>\n sstyled(styles)(\n <STabLineItem\n render={Box}\n tag='button'\n tabIndex={0}\n neighborLocation={neighborLocation}\n type='button'\n role='tab'\n >\n {addonLeft ? <TabLine.Item.Addon tag={addonLeft} /> : null}\n {addonTextChildren(Children, TabLine.Item.Text, TabLine.Item.Addon)}\n {addonRight ? <TabLine.Item.Addon tag={addonRight} /> : null}\n </STabLineItem>,\n )}\n </NeighborLocation.Detect>\n );\n}\n\nfunction Text(props) {\n const { styles } = props;\n const SText = Root;\n return sstyled(styles)(<SText render={Box} tag='span' />);\n}\n\nfunction Addon(props) {\n const { styles } = props;\n const SAddon = Root;\n return sstyled(styles)(<SAddon render={Box} tag='span' />);\n}\n\nconst TabLine = createComponent(TabLineRoot, {\n Item: [TabLineItem, { Text, Addon }],\n});\n\nexport const wrapTabLine = (wrapper) => wrapper;\n\nexport default TabLine;\n"],"mappings":";;;;;;;;;;;AAAA,SAASA,eAAe,EAAEC,SAAS,EAAEC,OAAO,EAAEC,IAAI,QAAQ,eAAe;AACzE,OAAOC,iBAAiB,MAAM,2CAA2C;AACzE,OAAOC,WAAW,MAAM,8CAA8C;AACtE,SAASC,GAAG,QAAQ,mBAAmB;AACvC,OAAOC,gBAAgB,MAAM,4BAA4B;AACzD,OAAOC,KAAK,MAAM,OAAO;AAAC;AAAA,IAAAC,KAAA,8BAAAC,QAAA,CAAAC,MAAA;AAAA;AAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAI1B,IAAMC,kBAAkB,GAAG;EACzBC,gBAAgB,EAAE,SAAlBA,gBAAgBA,CAAGC,eAAe,EAAEC,KAAK,EAAK;IAC5C,IAAID,eAAe,EAAE;MACnBA,eAAe,CAACE,KAAK,CAAC,CAAC;MACvB,IAAID,KAAK,CAAC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ACpB,IAAQ5B,MAAM,GAAK9E,KAAK,CAAhB8E,MAAM;EACd,IAAM6B,MAAM,GAC2BpH,GAAG;EAA1C,OAAAmH,KAAA,GAAOvH,OAAO,CAAC2F,MAAM,CAAC,eAACrF,KAAA,CAAAwF,aAAA,CAAC0B,MAAM,EAAAD,KAAA,CAAAxB,EAAA,WAAAzD,aAAA,KAAAmF,aAAA;IAAA,OAAkB;EAAM,GAAAH,KAAA,GAAE,CAAC;AAC3D;AAEA,IAAMT,OAAO,GAAG/G,eAAe,CAACoB,WAAW,EAAE;EAC3C4F,IAAI,EAAE,CAACX,WAAW,EAAE;IAAEc,IAAI,EAAJA,IAAI;IAAEF,KAAK,EAALA;EAAM,CAAC;AACrC,CAAC,CAAC;AAEF,OAAO,IAAMW,WAAW,GAAG,SAAdA,WAAWA,CAAIC,OAAO;EAAA,OAAKA,OAAO;AAAA;AAE/C,eAAed,OAAO","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"TabLine.js","names":["NeighborLocation","Box","createComponent","Component","sstyled","Root","addonTextChildren","a11yEnhance","Text","SemcoreText","React","style","_sstyled","insert","TabLineRoot","_Component","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","concat","_defineProperty","animation","undefined","createRef","_this$state$animation","state","started","setState","_objectSpread","value","e","handlers","_inherits","_createClass","key","uncontrolledProps","componentDidUpdate","prevValue","asProps","animate","componentDidMount","componentWillUnmount","animationStartTimeout","clearTimeout","fromNode","itemRefs","toString","toNode","containerNode","containerRef","current","containerRect","getBoundingClientRect","fromRect","toRect","fromLeft","x","fromWidth","width","toLeft","toWidth","setTimeout","handleAnimationStart","getItemProps","props","index","_this2","_this$asProps","size","isSelected","bindHandlerClick","ref","node","buttonRefsList","getItemTextProps","tabLineSize","getCaretProps","left","onTransitionEnd","handleAnimationEnd","render","_ref","_ref5","STabLine","SCaret","_this$asProps2","styles","Children","controlsLength","createElement","cn","_assignProps","defaultValue","underlined","behavior","onNeighborChange","neighborElement","focus","click","childSelector","TabLineItem","_ref2","arguments[0]","STabLineItem","addonLeft","addonRight","neighborLocation","buttonRef","useRef","Detect","_ref6","_assignProps2","TabLine","Item","Addon","tag","_ref3","_ref7","_props$ellipsis","ellipsis","SText","_assignProps3","_ref4","_ref8","SAddon","_assignProps4","wrapTabLine","wrapper"],"sources":["../../src/TabLine.tsx"],"sourcesContent":["import { NeighborLocation, Box } from '@semcore/base-components';\nimport type { Intergalactic } from '@semcore/core';\nimport { createComponent, Component, sstyled, Root } from '@semcore/core';\nimport addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';\nimport a11yEnhance from '@semcore/core/lib/utils/enhances/a11yEnhance';\nimport { Text as SemcoreText } from '@semcore/typography';\nimport React from 'react';\n\nimport style from './style/tab-line.shadow.css';\nimport type { NSTabLine } from './TabLine.type';\n\ntype State = {\n animation: {\n fromLeft: number;\n fromWidth: number;\n toLeft: number;\n toWidth: number;\n started: boolean;\n } | null;\n};\n\nclass TabLineRoot extends Component<\n Intergalactic.InternalTypings.InferComponentProps<NSTabLine.Component>,\n typeof TabLineRoot.enhance,\n NSTabLine.Handlers,\n {},\n State\n> {\n static displayName = 'TabLine';\n static style = style;\n static defaultProps = {\n defaultValue: null,\n size: 'm',\n underlined: true,\n behavior: 'auto',\n };\n\n static enhance = [a11yEnhance({\n onNeighborChange: (neighborElement, props) => {\n if (neighborElement) {\n neighborElement.focus();\n if (props.behavior === 'auto') {\n neighborElement.click();\n }\n }\n },\n childSelector: ['role', 'tab'],\n })] as const;\n\n state: State = { animation: null };\n prevValue: NSTabLine.Props['value'] = undefined;\n itemRefs: Record<string, HTMLDivElement> = {};\n containerRef = React.createRef<HTMLDivElement>();\n animationStartTimeout: ReturnType<typeof setTimeout> | null = null;\n buttonRefsList: Array<React.MutableRefObject<HTMLButtonElement | undefined>> = [];\n\n uncontrolledProps() {\n return {\n value: null,\n };\n }\n\n componentDidUpdate() {\n if (\n this.prevValue !== null &&\n this.asProps.value !== null &&\n this.prevValue !== this.asProps.value\n ) {\n this.animate();\n }\n this.prevValue = this.asProps.value;\n }\n\n componentDidMount() {\n this.prevValue = this.asProps.value;\n }\n\n componentWillUnmount() {\n if (this.animationStartTimeout) {\n clearTimeout(this.animationStartTimeout);\n }\n }\n\n animate() {\n if (this.prevValue === undefined || this.asProps.value === undefined) return;\n\n const fromNode = this.itemRefs[this.prevValue.toString()];\n const toNode = this.itemRefs[this.asProps.value.toString()];\n const containerNode = this.containerRef.current;\n\n if (!fromNode || !toNode || !containerNode) return;\n const containerRect = containerNode.getBoundingClientRect();\n const fromRect = fromNode.getBoundingClientRect();\n const toRect = toNode.getBoundingClientRect();\n const animation = {\n fromLeft: fromRect.x - containerRect.x,\n fromWidth: fromRect.width,\n toLeft: toRect.x - containerRect.x,\n toWidth: toRect.width,\n started: false,\n };\n this.setState({ animation });\n\n if (this.animationStartTimeout) {\n clearTimeout(this.animationStartTimeout);\n }\n\n this.animationStartTimeout = setTimeout(this.handleAnimationStart, 0);\n }\n\n handleAnimationStart = () => {\n if (this.state.animation?.started === false) {\n this.setState({ animation: { ...this.state.animation, started: true } });\n }\n };\n\n handleAnimationEnd = () => {\n this.setState({ animation: null });\n };\n\n bindHandlerClick = (value: NSTabLine.Props['value']) => (e: React.SyntheticEvent) => {\n this.handlers.value(value, e);\n };\n\n getItemProps(props: NSTabLine.Item.Props, index: number) {\n const { value, size } = this.asProps;\n const isSelected = value === props.value;\n return {\n size,\n 'selected': isSelected,\n 'onClick': this.bindHandlerClick(props.value),\n 'tabIndex': isSelected ? 0 : -1,\n 'aria-selected': isSelected,\n 'ref': (node: HTMLDivElement) => {\n if (props.value === undefined) return;\n\n this.itemRefs[props.value.toString()] = node;\n },\n 'buttonRefsList': this.buttonRefsList,\n index,\n };\n }\n\n getItemTextProps(props: NSTabLine.Item.Text.Props, index: number) {\n const { size: tabLineSize } = this.asProps;\n const size = props.size\n ? props.size\n : tabLineSize === 'm' ? 200 : 300;\n\n return {\n size,\n buttonRefsList: this.buttonRefsList,\n index,\n };\n }\n\n getCaretProps() {\n const { animation } = this.state;\n if (!animation) return {};\n if (animation.started) {\n return {\n style: {\n left: animation.toLeft,\n width: animation.toWidth,\n },\n onTransitionEnd: this.handleAnimationEnd,\n };\n } else {\n return {\n style: {\n left: animation.fromLeft,\n width: animation.fromWidth,\n },\n onTransitionEnd: this.handleAnimationEnd,\n };\n }\n }\n\n render() {\n const STabLine = Root;\n const SCaret = Box;\n const { styles, Children, controlsLength } = this.asProps;\n const { animation } = this.state;\n\n return sstyled(styles)(\n <STabLine render={Box} role='tablist' ref={this.containerRef}>\n <NeighborLocation controlsLength={controlsLength}>\n <Children />\n </NeighborLocation>\n {animation && <SCaret {...this.getCaretProps()} />}\n </STabLine>,\n );\n }\n}\n\nfunction TabLineItem(\n props: Intergalactic.InternalTypings.InferChildComponentProps<\n NSTabLine.Item.Component,\n typeof TabLineRoot,\n 'Item'\n >,\n) {\n const STabLineItem = Root;\n const { Children, styles, addonLeft, addonRight, neighborLocation, buttonRefsList, index } = props;\n const buttonRef = React.useRef<HTMLButtonElement>();\n\n buttonRefsList[index] = buttonRef;\n\n return (\n <NeighborLocation.Detect neighborLocation={neighborLocation}>\n {(neighborLocation) =>\n sstyled(styles)(\n <STabLineItem\n render={Box}\n tag='button'\n tabIndex={0}\n neighborLocation={neighborLocation}\n type='button'\n role='tab'\n ref={buttonRef}\n >\n {addonLeft ? <TabLine.Item.Addon tag={addonLeft} /> : null}\n {addonTextChildren(Children, TabLine.Item.Text, TabLine.Item.Addon)}\n {addonRight ? <TabLine.Item.Addon tag={addonRight} /> : null}\n </STabLineItem>,\n )}\n </NeighborLocation.Detect>\n );\n}\n\nfunction Text(\n props: Intergalactic.InternalTypings.InferChildComponentProps<\n NSTabLine.Item.Text.Component,\n typeof TabLineRoot,\n 'ItemText'\n >,\n) {\n const { styles, ellipsis = true, size, buttonRefsList, index } = props;\n const SText = Root;\n return sstyled(styles)(<SText render={SemcoreText} ellipsis={ellipsis} size={size} hint:triggerRef={buttonRefsList[index]} />);\n}\n\nfunction Addon(\n props: Intergalactic.InternalTypings.InferComponentProps<NSTabLine.Item.Addon.Component>,\n) {\n const { styles } = props;\n const SAddon = Root;\n return sstyled(styles)(<SAddon render={Box} tag='span' />);\n}\n\nconst TabLine = createComponent(TabLineRoot, {\n Item: [TabLineItem, { Text, Addon }],\n}) as unknown as NSTabLine.Component;\n\nexport const wrapTabLine = <PropsExtending extends {}>(wrapper: (\n props: Intergalactic.InternalTypings.UntypeRefAndTag<\n Intergalactic.InternalTypings.ComponentPropsNesting<NSTabLine.WrapperComponent>\n > &\n PropsExtending,\n) => React.ReactNode) => wrapper as NSTabLine.WrapperComponent<PropsExtending>;\n\nexport default TabLine;\n"],"mappings":";;;;;;;;;;;AAAA,SAASA,gBAAgB,EAAEC,GAAG,QAAQ,0BAA0B;AAEhE,SAASC,eAAe,EAAEC,SAAS,EAAEC,OAAO,EAAEC,IAAI,QAAQ,eAAe;AACzE,OAAOC,iBAAiB,MAAM,2CAA2C;AACzE,OAAOC,WAAW,MAAM,8CAA8C;AACtE,SAASC,IAAI,IAAIC,WAAW,QAAQ,qBAAqB;AACzD,OAAOC,KAAK,MAAM,OAAO;AAAC;AAAA,IAAAC,KAAA,8BAAAC,QAAA,CAAAC,MAAA;AAAA;AAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,IAepBC,WAAW,0BAAAC,UAAA;EAAA,SAAAD,YAAA;IAAA,IAAAE,KAAA;IAAAC,eAAA,OAAAH,WAAA;IAAA,SAAAI,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAQ,UAAA,OAAAV,WAAA,KAAAW,MAAA,CAAAJ,IAAA;IAAAK,eAA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AqF,aAAA,CAACmC,MAAM,EAAAD,KAAA,CAAAjC,EAAA,WAAA9D,aAAA,KAAAiG,aAAA;IAAA,OAAkB;EAAM,GAAAH,KAAA,GAAE,CAAC;AAC3D;AAEA,IAAMV,OAAO,GAAGpH,eAAe,CAACY,WAAW,EAAE;EAC3CyG,IAAI,EAAE,CAACb,WAAW,EAAE;IAAElG,IAAI,EAAJA,IAAI;IAAEgH,KAAK,EAALA;EAAM,CAAC;AACrC,CAAC,CAAmC;AAEpC,OAAO,IAAMY,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,OAKnC;EAAA,OAAKA,OAAO;AAAA,CAA8C;AAE9E,eAAef,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabLine.type.js","names":[],"sources":["../../src/TabLine.type.ts"],"sourcesContent":["import type { Box, BoxProps, NeighborItemProps, NeighborLocationProps } from '@semcore/base-components';\nimport type { PropGetterFn, Intergalactic } from '@semcore/core';\nimport type { NSText } from '@semcore/typography';\nimport type React from 'react';\n\ndeclare namespace NSTabLine {\n type Value = string | number | boolean;\n type Props<T extends NSTabLine.Value = NSTabLine.Value> = BoxProps &\n NeighborLocationProps & {\n /** TabLine size\n * @default m\n * */\n size?: 'm' | 'l' | false;\n /** Adds a bottom border for the entire component\n * @default true\n * */\n underlined?: boolean;\n /** Is invoked when changing the selection */\n onChange?:\n | ((value: T, e?: React.SyntheticEvent<HTMLButtonElement>) => void)\n | React.Dispatch<React.SetStateAction<T>>;\n /** Value of the selected tab */\n value?: T;\n /** Default value of the selected tab\n * @default null\n * */\n defaultValue?: T;\n\n /**\n * Behavior of tabs.\n * In `auto`, changes the tab immediately when press arrow.\n * In `manual`, needs to press `space` or `enter` for select a choice.\n * @default 'auto'\n */\n behavior?: 'auto' | 'manual';\n };\n type Ctx = {\n getItemProps: PropGetterFn;\n };\n type Handlers = {\n value: null;\n };\n\n namespace Item {\n type Props = BoxProps &\n NeighborItemProps & {\n /** Makes a tab selected. This property is determined automatically depending on the value. */\n selected?: boolean;\n /** Disabled state */\n disabled?: boolean;\n /** Tab value */\n value?: NSTabLine.Value;\n /** Left addon tag */\n addonLeft?: React.ElementType;\n /** Right addon tag */\n addonRight?: React.ElementType;\n };\n\n namespace Text {\n type Props = NSText.Props;\n type Component = NSText.Component;\n }\n\n namespace Addon {\n type Component = typeof Box;\n }\n\n type Component = Intergalactic.Component<'div', Props, {}, [handlers: NSTabLine.Handlers]> & {\n Text: Text.Component;\n Addon: Addon.Component;\n };\n }\n\n type WrapperComponent<PropsExtending = {}> = (<\n V extends Value,\n Tag extends Intergalactic.Tag = 'div',\n >(\n props: Intergalactic.InternalTypings.ComponentProps<\n Tag,\n 'div',\n Props<V>,\n Ctx,\n [handlers: Handlers]\n > &\n PropsExtending,\n ) => Intergalactic.InternalTypings.ComponentRenderingResults) &\n Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', Props>;\n\n type Component = WrapperComponent & {\n Item: Item.Component;\n };\n}\n\n/** @deprecated It will be removed in v18. */\nexport type TabLineValue = NSTabLine.Value;\n/** @deprecated It will be removed in v18. */\nexport type TabLineProps<T extends TabLineValue = TabLineValue> = NSTabLine.Props<T>;\n/** @deprecated It will be removed in v18. */\nexport type TabLineItemProps = NSTabLine.Item.Props;\n/** @deprecated It will be removed in v18. */\nexport type TabLineContext = NSTabLine.Ctx;\n/** @deprecated It will be removed in v18. */\nexport type TabLineHandlers = NSTabLine.Handlers;\n\nexport type { NSTabLine };\n"],"mappings":"","ignoreList":[]}
|
package/lib/es6/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default } from './TabLine';
|
|
2
|
-
export * from './TabLine';
|
|
1
|
+
export { default, wrapTabLine } from './TabLine';
|
|
2
|
+
export * from './TabLine.type';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/es6/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default"],"sources":["../../src/index.
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","wrapTabLine"],"sources":["../../src/index.ts"],"sourcesContent":["export { default, wrapTabLine } from './TabLine';\nexport * from './TabLine.type';\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,WAAW,QAAQ,WAAW;AAChD,cAAc,gBAAgB","ignoreList":[]}
|
|
@@ -66,7 +66,7 @@ STabLineItem {
|
|
|
66
66
|
|
|
67
67
|
&[selected]::after {
|
|
68
68
|
transition-delay: calc(var(--intergalactic-duration-control, 200) * 1ms);
|
|
69
|
-
background-color: var(--intergalactic-border-info-active, oklch(0.
|
|
69
|
+
background-color: var(--intergalactic-border-info-active, oklch(0.7 0.131 275.2));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
& SText:not(:last-child) {
|
|
@@ -82,7 +82,7 @@ SCaret {
|
|
|
82
82
|
position: absolute;
|
|
83
83
|
bottom: -1px;
|
|
84
84
|
height: 3px;
|
|
85
|
-
background: var(--intergalactic-border-info-active, oklch(0.
|
|
85
|
+
background: var(--intergalactic-border-info-active, oklch(0.7 0.131 275.2));
|
|
86
86
|
transition: calc(var(--intergalactic-duration-control, 200) * 1ms) all ease-in-out;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -97,13 +97,6 @@ STabLineItem[disabled] {
|
|
|
97
97
|
pointer-events: none;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
SText {
|
|
101
|
-
display: inline-block;
|
|
102
|
-
white-space: nowrap;
|
|
103
|
-
overflow: hidden;
|
|
104
|
-
text-overflow: ellipsis;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
100
|
SAddon {
|
|
108
101
|
display: inline-flex;
|
|
109
102
|
align-items: center;
|
|
@@ -113,21 +106,11 @@ SAddon {
|
|
|
113
106
|
STabLineItem[size='m'] {
|
|
114
107
|
height: 28px;
|
|
115
108
|
min-width: 18px;
|
|
116
|
-
|
|
117
|
-
& SText {
|
|
118
|
-
font-size: var(--intergalactic-fs-200, 14px);
|
|
119
|
-
line-height: var(--intergalactic-lh-200, 142%);
|
|
120
|
-
}
|
|
121
109
|
}
|
|
122
110
|
|
|
123
111
|
STabLineItem[size='l'] {
|
|
124
112
|
height: 40px;
|
|
125
113
|
min-width: 26px;
|
|
126
|
-
|
|
127
|
-
& SText {
|
|
128
|
-
font-size: var(--intergalactic-fs-300, 16px);
|
|
129
|
-
line-height: var(--intergalactic-lh-300, 150%);
|
|
130
|
-
}
|
|
131
114
|
}
|
|
132
115
|
|
|
133
116
|
STabLineItem[neighborLocation='left'] {
|
package/lib/esm/TabLine.mjs
CHANGED
|
@@ -4,46 +4,35 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
4
4
|
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
5
5
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
6
6
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import {
|
|
7
|
+
import { sstyled, assignProps, Component, createComponent } from "@semcore/core";
|
|
8
|
+
import { Box, NeighborLocation } from "@semcore/base-components";
|
|
8
9
|
import addonTextChildren from "@semcore/core/lib/utils/addonTextChildren";
|
|
9
10
|
import a11yEnhance from "@semcore/core/lib/utils/enhances/a11yEnhance";
|
|
10
|
-
import {
|
|
11
|
-
import NeighborLocation from "@semcore/neighbor-location";
|
|
11
|
+
import { Text as Text$1 } from "@semcore/typography";
|
|
12
12
|
import React from "react";
|
|
13
13
|
/*!__reshadow-styles__:"./style/tab-line.shadow.css"*/
|
|
14
14
|
var style = (
|
|
15
15
|
/*__reshadow_css_start__*/
|
|
16
16
|
(sstyled.insert(
|
|
17
17
|
/*__inner_css_start__*/
|
|
18
|
-
'.
|
|
18
|
+
'.___STabLine_1qpi7_gg_{position:relative;display:flex;width:100%;max-width:100%}.___STabLine_1qpi7_gg_.__underlined_1qpi7_gg_{border-bottom:1px solid var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@supports (color:color(display-p3 0 0 0%)){.___STabLine_1qpi7_gg_.__underlined_1qpi7_gg_{border-bottom:1px solid var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@media (color-gamut:p3){.___STabLine_1qpi7_gg_.__underlined_1qpi7_gg_{border-bottom:1px solid var(--intergalactic-border-primary, color(display-p3 0.00798 0.04498 0.03219 / 0.161))}}}.___STabLineItem_1qpi7_gg_{display:inline-flex;align-items:center;justify-content:center;position:relative;touch-action:manipulation;white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;user-select:none;box-sizing:border-box;padding:0;margin:0;box-shadow:none;-webkit-text-decoration:none;text-decoration:none;-webkit-tap-highlight-color:transparent;overflow:visible;text-align:center;vertical-align:middle;font-family:inherit;cursor:pointer;border:0;background:0 0;color:var(--intergalactic-text-primary, rgba(1, 5, 0, 0.899));margin-right:var(--intergalactic-spacing-4x, 16px);font-weight:var(--intergalactic-medium, 500)}.___STabLineItem_1qpi7_gg_::-moz-focus-inner{border:0;padding:0}.___STabLineItem_1qpi7_gg_:active{-webkit-text-decoration:none;text-decoration:none}@media (hover:hover){.___STabLineItem_1qpi7_gg_:hover{-webkit-text-decoration:none;text-decoration:none}}.___STabLineItem_1qpi7_gg_::after,.___STabLineItem_1qpi7_gg_::before{content:"";position:absolute;left:0;bottom:-1px;height:3px;width:100%;background-color:transparent}.___STabLineItem_1qpi7_gg_::before{transition:background-color calc(var(--intergalactic-duration-control, 200)*1ms) ease-in-out}@media (hover:hover){.___STabLineItem_1qpi7_gg_:hover::before{background-color:var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@supports (color:color(display-p3 0 0 0%)){.___STabLineItem_1qpi7_gg_:hover::before{background-color:var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@media (color-gamut:p3){.___STabLineItem_1qpi7_gg_:hover::before{background-color:var(--intergalactic-border-primary, color(display-p3 0.00798 0.04498 0.03219 / 0.161))}}}}.___STabLineItem_1qpi7_gg_.__selected_1qpi7_gg_::after{transition-delay:calc(var(--intergalactic-duration-control, 200)*1ms);background-color:var(--intergalactic-border-info-active, rgb(135, 150, 239))}.___STabLineItem_1qpi7_gg_ .___SAddon_1qpi7_gg_:not(:last-child),.___STabLineItem_1qpi7_gg_ .___SText_1qpi7_gg_:not(:last-child){margin-right:var(--intergalactic-spacing-2x, 8px)}.___SCaret_1qpi7_gg_{position:absolute;bottom:-1px;height:3px;background:var(--intergalactic-border-info-active, rgb(135, 150, 239));transition:calc(var(--intergalactic-duration-control, 200)*1ms) all ease-in-out}.___STabLineItem_1qpi7_gg_.__selected_1qpi7_gg_{flex-shrink:0}.___STabLineItem_1qpi7_gg_.__disabled_1qpi7_gg_{opacity:var(--intergalactic-disabled-opacity, 0.4);cursor:default;pointer-events:none}.___SAddon_1qpi7_gg_{display:inline-flex;align-items:center;justify-content:center}.___STabLineItem_1qpi7_gg_._size_m_1qpi7_gg_{height:28px;min-width:18px}.___STabLineItem_1qpi7_gg_._size_l_1qpi7_gg_{height:40px;min-width:26px}.___STabLineItem_1qpi7_gg_._neighborLocation_left_1qpi7_gg_{margin-right:0}@media (prefers-reduced-motion){.___STabLineItem_1qpi7_gg_.__selected_1qpi7_gg_::after,.___STabLineItem_1qpi7_gg_::after,.___STabLineItem_1qpi7_gg_::before{transition:none}.___SCaret_1qpi7_gg_{display:none}}',
|
|
19
19
|
/*__inner_css_end__*/
|
|
20
|
-
"
|
|
20
|
+
"1qpi7_gg_"
|
|
21
21
|
), /*__reshadow_css_end__*/
|
|
22
22
|
{
|
|
23
|
-
"__STabLine": "
|
|
24
|
-
"_underlined": "
|
|
25
|
-
"__SCaret": "
|
|
26
|
-
"__STabLineItem": "
|
|
27
|
-
"_selected": "
|
|
28
|
-
"_disabled": "
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
23
|
+
"__STabLine": "___STabLine_1qpi7_gg_",
|
|
24
|
+
"_underlined": "__underlined_1qpi7_gg_",
|
|
25
|
+
"__SCaret": "___SCaret_1qpi7_gg_",
|
|
26
|
+
"__STabLineItem": "___STabLineItem_1qpi7_gg_",
|
|
27
|
+
"_selected": "__selected_1qpi7_gg_",
|
|
28
|
+
"_disabled": "__disabled_1qpi7_gg_",
|
|
29
|
+
"__SAddon": "___SAddon_1qpi7_gg_",
|
|
30
|
+
"_size_m": "_size_m_1qpi7_gg_",
|
|
31
|
+
"_size_l": "_size_l_1qpi7_gg_",
|
|
32
|
+
"_neighborLocation_left": "_neighborLocation_left_1qpi7_gg_",
|
|
33
|
+
"__SText": "___SText_1qpi7_gg_"
|
|
34
34
|
})
|
|
35
35
|
);
|
|
36
|
-
var optionsA11yEnhance = {
|
|
37
|
-
onNeighborChange: function onNeighborChange(neighborElement, props) {
|
|
38
|
-
if (neighborElement) {
|
|
39
|
-
neighborElement.focus();
|
|
40
|
-
if (props.behavior === "auto") {
|
|
41
|
-
neighborElement.click();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
childSelector: ["role", "tab"]
|
|
46
|
-
};
|
|
47
36
|
var TabLineRoot = /* @__PURE__ */ (function(_Component) {
|
|
48
37
|
function TabLineRoot2() {
|
|
49
38
|
var _this;
|
|
@@ -58,7 +47,8 @@ var TabLineRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
58
47
|
_defineProperty(_this, "prevValue", void 0);
|
|
59
48
|
_defineProperty(_this, "itemRefs", {});
|
|
60
49
|
_defineProperty(_this, "containerRef", /* @__PURE__ */ React.createRef());
|
|
61
|
-
_defineProperty(_this, "animationStartTimeout",
|
|
50
|
+
_defineProperty(_this, "animationStartTimeout", null);
|
|
51
|
+
_defineProperty(_this, "buttonRefsList", []);
|
|
62
52
|
_defineProperty(_this, "handleAnimationStart", function() {
|
|
63
53
|
var _this$state$animation;
|
|
64
54
|
if (((_this$state$animation = _this.state.animation) === null || _this$state$animation === void 0 ? void 0 : _this$state$animation.started) === false) {
|
|
@@ -105,13 +95,16 @@ var TabLineRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
105
95
|
}, {
|
|
106
96
|
key: "componentWillUnmount",
|
|
107
97
|
value: function componentWillUnmount() {
|
|
108
|
-
|
|
98
|
+
if (this.animationStartTimeout) {
|
|
99
|
+
clearTimeout(this.animationStartTimeout);
|
|
100
|
+
}
|
|
109
101
|
}
|
|
110
102
|
}, {
|
|
111
103
|
key: "animate",
|
|
112
104
|
value: function animate() {
|
|
113
|
-
|
|
114
|
-
var
|
|
105
|
+
if (this.prevValue === void 0 || this.asProps.value === void 0) return;
|
|
106
|
+
var fromNode = this.itemRefs[this.prevValue.toString()];
|
|
107
|
+
var toNode = this.itemRefs[this.asProps.value.toString()];
|
|
115
108
|
var containerNode = this.containerRef.current;
|
|
116
109
|
if (!fromNode || !toNode || !containerNode) return;
|
|
117
110
|
var containerRect = containerNode.getBoundingClientRect();
|
|
@@ -127,12 +120,14 @@ var TabLineRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
127
120
|
this.setState({
|
|
128
121
|
animation
|
|
129
122
|
});
|
|
130
|
-
|
|
123
|
+
if (this.animationStartTimeout) {
|
|
124
|
+
clearTimeout(this.animationStartTimeout);
|
|
125
|
+
}
|
|
131
126
|
this.animationStartTimeout = setTimeout(this.handleAnimationStart, 0);
|
|
132
127
|
}
|
|
133
128
|
}, {
|
|
134
129
|
key: "getItemProps",
|
|
135
|
-
value: function getItemProps(props,
|
|
130
|
+
value: function getItemProps(props, index) {
|
|
136
131
|
var _this2 = this;
|
|
137
132
|
var _this$asProps = this.asProps, value = _this$asProps.value, size = _this$asProps.size;
|
|
138
133
|
var isSelected = value === props.value;
|
|
@@ -143,8 +138,22 @@ var TabLineRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
143
138
|
"tabIndex": isSelected ? 0 : -1,
|
|
144
139
|
"aria-selected": isSelected,
|
|
145
140
|
"ref": function ref(node) {
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
if (props.value === void 0) return;
|
|
142
|
+
_this2.itemRefs[props.value.toString()] = node;
|
|
143
|
+
},
|
|
144
|
+
"buttonRefsList": this.buttonRefsList,
|
|
145
|
+
index
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "getItemTextProps",
|
|
150
|
+
value: function getItemTextProps(props, index) {
|
|
151
|
+
var tabLineSize = this.asProps.size;
|
|
152
|
+
var size = props.size ? props.size : tabLineSize === "m" ? 200 : 300;
|
|
153
|
+
return {
|
|
154
|
+
size,
|
|
155
|
+
buttonRefsList: this.buttonRefsList,
|
|
156
|
+
index
|
|
148
157
|
};
|
|
149
158
|
}
|
|
150
159
|
}, {
|
|
@@ -195,11 +204,23 @@ _defineProperty(TabLineRoot, "defaultProps", {
|
|
|
195
204
|
underlined: true,
|
|
196
205
|
behavior: "auto"
|
|
197
206
|
});
|
|
198
|
-
_defineProperty(TabLineRoot, "enhance", [a11yEnhance(
|
|
207
|
+
_defineProperty(TabLineRoot, "enhance", [a11yEnhance({
|
|
208
|
+
onNeighborChange: function onNeighborChange(neighborElement, props) {
|
|
209
|
+
if (neighborElement) {
|
|
210
|
+
neighborElement.focus();
|
|
211
|
+
if (props.behavior === "auto") {
|
|
212
|
+
neighborElement.click();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
childSelector: ["role", "tab"]
|
|
217
|
+
})]);
|
|
199
218
|
function TabLineItem(props) {
|
|
200
219
|
var _ref2 = arguments[0];
|
|
201
220
|
var STabLineItem = Box;
|
|
202
|
-
var Children = props.Children, styles = props.styles, addonLeft = props.addonLeft, addonRight = props.addonRight, neighborLocation = props.neighborLocation;
|
|
221
|
+
var Children = props.Children, styles = props.styles, addonLeft = props.addonLeft, addonRight = props.addonRight, neighborLocation = props.neighborLocation, buttonRefsList = props.buttonRefsList, index = props.index;
|
|
222
|
+
var buttonRef = React.useRef();
|
|
223
|
+
buttonRefsList[index] = buttonRef;
|
|
203
224
|
return /* @__PURE__ */ React.createElement(NeighborLocation.Detect, {
|
|
204
225
|
neighborLocation
|
|
205
226
|
}, function(neighborLocation2) {
|
|
@@ -209,7 +230,8 @@ function TabLineItem(props) {
|
|
|
209
230
|
"tabIndex": 0,
|
|
210
231
|
"neighborLocation": neighborLocation2,
|
|
211
232
|
"type": "button",
|
|
212
|
-
"role": "tab"
|
|
233
|
+
"role": "tab",
|
|
234
|
+
"ref": buttonRef
|
|
213
235
|
}, _ref2))), addonLeft ? /* @__PURE__ */ React.createElement(TabLine.Item.Addon, {
|
|
214
236
|
tag: addonLeft
|
|
215
237
|
}) : null, addonTextChildren(Children, TabLine.Item.Text, TabLine.Item.Addon), addonRight ? /* @__PURE__ */ React.createElement(TabLine.Item.Addon, {
|
|
@@ -219,10 +241,12 @@ function TabLineItem(props) {
|
|
|
219
241
|
}
|
|
220
242
|
function Text(props) {
|
|
221
243
|
var _ref3 = arguments[0], _ref7;
|
|
222
|
-
var styles = props.styles;
|
|
223
|
-
var SText =
|
|
244
|
+
var styles = props.styles, _props$ellipsis = props.ellipsis, ellipsis = _props$ellipsis === void 0 ? true : _props$ellipsis, size = props.size, buttonRefsList = props.buttonRefsList, index = props.index;
|
|
245
|
+
var SText = Text$1;
|
|
224
246
|
return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SText, _ref7.cn("SText", _objectSpread({}, assignProps({
|
|
225
|
-
"
|
|
247
|
+
"ellipsis": ellipsis,
|
|
248
|
+
"size": size,
|
|
249
|
+
"hint:triggerRef": buttonRefsList[index]
|
|
226
250
|
}, _ref3))));
|
|
227
251
|
}
|
|
228
252
|
function Addon(props) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/esm/index.mjs
CHANGED
|
@@ -66,7 +66,7 @@ STabLineItem {
|
|
|
66
66
|
|
|
67
67
|
&[selected]::after {
|
|
68
68
|
transition-delay: calc(var(--intergalactic-duration-control, 200) * 1ms);
|
|
69
|
-
background-color: var(--intergalactic-border-info-active, oklch(0.
|
|
69
|
+
background-color: var(--intergalactic-border-info-active, oklch(0.7 0.131 275.2));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
& SText:not(:last-child) {
|
|
@@ -82,7 +82,7 @@ SCaret {
|
|
|
82
82
|
position: absolute;
|
|
83
83
|
bottom: -1px;
|
|
84
84
|
height: 3px;
|
|
85
|
-
background: var(--intergalactic-border-info-active, oklch(0.
|
|
85
|
+
background: var(--intergalactic-border-info-active, oklch(0.7 0.131 275.2));
|
|
86
86
|
transition: calc(var(--intergalactic-duration-control, 200) * 1ms) all ease-in-out;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -97,13 +97,6 @@ STabLineItem[disabled] {
|
|
|
97
97
|
pointer-events: none;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
SText {
|
|
101
|
-
display: inline-block;
|
|
102
|
-
white-space: nowrap;
|
|
103
|
-
overflow: hidden;
|
|
104
|
-
text-overflow: ellipsis;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
100
|
SAddon {
|
|
108
101
|
display: inline-flex;
|
|
109
102
|
align-items: center;
|
|
@@ -113,21 +106,11 @@ SAddon {
|
|
|
113
106
|
STabLineItem[size='m'] {
|
|
114
107
|
height: 28px;
|
|
115
108
|
min-width: 18px;
|
|
116
|
-
|
|
117
|
-
& SText {
|
|
118
|
-
font-size: var(--intergalactic-fs-200, 14px);
|
|
119
|
-
line-height: var(--intergalactic-lh-200, 142%);
|
|
120
|
-
}
|
|
121
109
|
}
|
|
122
110
|
|
|
123
111
|
STabLineItem[size='l'] {
|
|
124
112
|
height: 40px;
|
|
125
113
|
min-width: 26px;
|
|
126
|
-
|
|
127
|
-
& SText {
|
|
128
|
-
font-size: var(--intergalactic-fs-300, 16px);
|
|
129
|
-
line-height: var(--intergalactic-lh-300, 150%);
|
|
130
|
-
}
|
|
131
114
|
}
|
|
132
115
|
|
|
133
116
|
STabLineItem[neighborLocation='left'] {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Intergalactic } from '@semcore/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { NSTabLine } from './TabLine.type';
|
|
4
|
+
declare const TabLine: NSTabLine.Component;
|
|
5
|
+
export declare const wrapTabLine: <PropsExtending extends {}>(wrapper: (props: Intergalactic.InternalTypings.UntypeRefAndTag<Intergalactic.InternalTypings.ComponentPropsNesting<NSTabLine.WrapperComponent>> & PropsExtending) => React.ReactNode) => NSTabLine.WrapperComponent<PropsExtending>;
|
|
6
|
+
export default TabLine;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Box, BoxProps, NeighborItemProps, NeighborLocationProps } from '@semcore/base-components';
|
|
2
|
+
import type { PropGetterFn, Intergalactic } from '@semcore/core';
|
|
3
|
+
import type { NSText } from '@semcore/typography';
|
|
4
|
+
import type React from 'react';
|
|
5
|
+
declare namespace NSTabLine {
|
|
6
|
+
type Value = string | number | boolean;
|
|
7
|
+
type Props<T extends NSTabLine.Value = NSTabLine.Value> = BoxProps & NeighborLocationProps & {
|
|
8
|
+
/** TabLine size
|
|
9
|
+
* @default m
|
|
10
|
+
* */
|
|
11
|
+
size?: 'm' | 'l' | false;
|
|
12
|
+
/** Adds a bottom border for the entire component
|
|
13
|
+
* @default true
|
|
14
|
+
* */
|
|
15
|
+
underlined?: boolean;
|
|
16
|
+
/** Is invoked when changing the selection */
|
|
17
|
+
onChange?: ((value: T, e?: React.SyntheticEvent<HTMLButtonElement>) => void) | React.Dispatch<React.SetStateAction<T>>;
|
|
18
|
+
/** Value of the selected tab */
|
|
19
|
+
value?: T;
|
|
20
|
+
/** Default value of the selected tab
|
|
21
|
+
* @default null
|
|
22
|
+
* */
|
|
23
|
+
defaultValue?: T;
|
|
24
|
+
/**
|
|
25
|
+
* Behavior of tabs.
|
|
26
|
+
* In `auto`, changes the tab immediately when press arrow.
|
|
27
|
+
* In `manual`, needs to press `space` or `enter` for select a choice.
|
|
28
|
+
* @default 'auto'
|
|
29
|
+
*/
|
|
30
|
+
behavior?: 'auto' | 'manual';
|
|
31
|
+
};
|
|
32
|
+
type Ctx = {
|
|
33
|
+
getItemProps: PropGetterFn;
|
|
34
|
+
};
|
|
35
|
+
type Handlers = {
|
|
36
|
+
value: null;
|
|
37
|
+
};
|
|
38
|
+
namespace Item {
|
|
39
|
+
type Props = BoxProps & NeighborItemProps & {
|
|
40
|
+
/** Makes a tab selected. This property is determined automatically depending on the value. */
|
|
41
|
+
selected?: boolean;
|
|
42
|
+
/** Disabled state */
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/** Tab value */
|
|
45
|
+
value?: NSTabLine.Value;
|
|
46
|
+
/** Left addon tag */
|
|
47
|
+
addonLeft?: React.ElementType;
|
|
48
|
+
/** Right addon tag */
|
|
49
|
+
addonRight?: React.ElementType;
|
|
50
|
+
};
|
|
51
|
+
namespace Text {
|
|
52
|
+
type Props = NSText.Props;
|
|
53
|
+
type Component = NSText.Component;
|
|
54
|
+
}
|
|
55
|
+
namespace Addon {
|
|
56
|
+
type Component = typeof Box;
|
|
57
|
+
}
|
|
58
|
+
type Component = Intergalactic.Component<'div', Props, {}, [handlers: NSTabLine.Handlers]> & {
|
|
59
|
+
Text: Text.Component;
|
|
60
|
+
Addon: Addon.Component;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
type WrapperComponent<PropsExtending = {}> = (<V extends Value, Tag extends Intergalactic.Tag = 'div'>(props: Intergalactic.InternalTypings.ComponentProps<Tag, 'div', Props<V>, Ctx, [
|
|
64
|
+
handlers: Handlers
|
|
65
|
+
]> & PropsExtending) => Intergalactic.InternalTypings.ComponentRenderingResults) & Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', Props>;
|
|
66
|
+
type Component = WrapperComponent & {
|
|
67
|
+
Item: Item.Component;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** @deprecated It will be removed in v18. */
|
|
71
|
+
export type TabLineValue = NSTabLine.Value;
|
|
72
|
+
/** @deprecated It will be removed in v18. */
|
|
73
|
+
export type TabLineProps<T extends TabLineValue = TabLineValue> = NSTabLine.Props<T>;
|
|
74
|
+
/** @deprecated It will be removed in v18. */
|
|
75
|
+
export type TabLineItemProps = NSTabLine.Item.Props;
|
|
76
|
+
/** @deprecated It will be removed in v18. */
|
|
77
|
+
export type TabLineContext = NSTabLine.Ctx;
|
|
78
|
+
/** @deprecated It will be removed in v18. */
|
|
79
|
+
export type TabLineHandlers = NSTabLine.Handlers;
|
|
80
|
+
export type { NSTabLine };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,102 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { NeighborItemProps, NeighborLocationProps } from '@semcore/neighbor-location';
|
|
4
|
-
import type React from 'react';
|
|
5
|
-
|
|
6
|
-
export type TabLineValue = string | number | boolean;
|
|
7
|
-
|
|
8
|
-
/** @deprecated */
|
|
9
|
-
export interface ITabLineProps<T extends TabLineValue = TabLineValue>
|
|
10
|
-
extends TabLineProps<T>,
|
|
11
|
-
UnknownProperties {}
|
|
12
|
-
export type TabLineProps<T extends TabLineValue = TabLineValue> = BoxProps &
|
|
13
|
-
NeighborLocationProps & {
|
|
14
|
-
/** TabLine size
|
|
15
|
-
* @default m
|
|
16
|
-
* */
|
|
17
|
-
size?: 'm' | 'l' | false;
|
|
18
|
-
/** Adds a bottom border for the entire component
|
|
19
|
-
* @default true
|
|
20
|
-
* */
|
|
21
|
-
underlined?: boolean;
|
|
22
|
-
/** Is invoked when changing the selection */
|
|
23
|
-
onChange?:
|
|
24
|
-
| ((value: T, e?: React.SyntheticEvent<HTMLButtonElement>) => void)
|
|
25
|
-
| React.Dispatch<React.SetStateAction<T>>;
|
|
26
|
-
/** Value of the selected tab */
|
|
27
|
-
value?: T;
|
|
28
|
-
/** Default value of the selected tab
|
|
29
|
-
* @default null
|
|
30
|
-
* */
|
|
31
|
-
defaultValue?: T;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Behavior of tabs.
|
|
35
|
-
* In `auto`, changes the tab immediately when press arrow.
|
|
36
|
-
* In `manual`, needs to press `space` or `enter` for select a choice.
|
|
37
|
-
* @default 'auto'
|
|
38
|
-
*/
|
|
39
|
-
behavior?: 'auto' | 'manual';
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** @deprecated */
|
|
43
|
-
export interface ITabLineItemProps extends TabLineItemProps, UnknownProperties {}
|
|
44
|
-
export type TabLineItemProps = BoxProps &
|
|
45
|
-
NeighborItemProps & {
|
|
46
|
-
/** Makes a tab selected. This property is determined automatically depending on the value. */
|
|
47
|
-
selected?: boolean;
|
|
48
|
-
/** Disabled state */
|
|
49
|
-
disabled?: boolean;
|
|
50
|
-
/** Tab value */
|
|
51
|
-
value?: TabLineValue;
|
|
52
|
-
/** Left addon tag */
|
|
53
|
-
addonLeft?: React.ElementType;
|
|
54
|
-
/** Right addon tag */
|
|
55
|
-
addonRight?: React.ElementType;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/** @deprecated */
|
|
59
|
-
export interface ITabLineContext extends TabLineContext, UnknownProperties {}
|
|
60
|
-
export type TabLineContext = {
|
|
61
|
-
getItemProps: PropGetterFn;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/** @deprecated */
|
|
65
|
-
export interface ITabLineHandlers extends TabLineHandlers, UnknownProperties {}
|
|
66
|
-
export type TabLineHandlers = {
|
|
67
|
-
value: (value: TabLineValue) => void;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
type IntergalacticTabLineComponent<PropsExtending = {}> = (<
|
|
71
|
-
Value extends TabLineValue,
|
|
72
|
-
Tag extends Intergalactic.Tag = 'div',
|
|
73
|
-
>(
|
|
74
|
-
props: Intergalactic.InternalTypings.ComponentProps<
|
|
75
|
-
Tag,
|
|
76
|
-
'div',
|
|
77
|
-
TabLineProps<Value>,
|
|
78
|
-
TabLineContext,
|
|
79
|
-
[handlers: TabLineHandlers]
|
|
80
|
-
> &
|
|
81
|
-
PropsExtending,
|
|
82
|
-
) => Intergalactic.InternalTypings.ComponentRenderingResults) &
|
|
83
|
-
Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', TabLineProps>;
|
|
84
|
-
|
|
85
|
-
declare const TabLine: IntergalacticTabLineComponent & {
|
|
86
|
-
Item: Intergalactic.Component<'div', TabLineItemProps, {}, [handlers: TabLineHandlers]> & {
|
|
87
|
-
Text: typeof Box;
|
|
88
|
-
Addon: typeof Box;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
declare const wrapTabLine: <PropsExtending extends {}>(
|
|
93
|
-
wrapper: (
|
|
94
|
-
props: Intergalactic.InternalTypings.UntypeRefAndTag<
|
|
95
|
-
Intergalactic.InternalTypings.ComponentPropsNesting<IntergalacticTabLineComponent>
|
|
96
|
-
> &
|
|
97
|
-
PropsExtending,
|
|
98
|
-
) => React.ReactNode,
|
|
99
|
-
) => IntergalacticTabLineComponent<PropsExtending>;
|
|
100
|
-
export { wrapTabLine };
|
|
101
|
-
|
|
102
|
-
export default TabLine;
|
|
1
|
+
export { default, wrapTabLine } from './TabLine';
|
|
2
|
+
export * from './TabLine.type';
|