-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tabs): add element customization (#1840)
- Loading branch information
Showing
10 changed files
with
729 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/tabs': minor | ||
'@twilio-paste/core': minor | ||
--- | ||
|
||
[Tabs]: Enable Component to respect element customizations set on the customization provider. Component now enables setting an element name on the underlying HTML element and checks the emotion theme object to determine whether it should merge in custom styles to the ones set by the component author. |
337 changes: 337 additions & 0 deletions
337
packages/paste-core/components/tabs/__tests__/tabs.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import {Box, safelySpreadBoxProps} from '@twilio-paste/box'; | ||
import type {BoxProps} from '@twilio-paste/box'; | ||
|
||
import {TabsContext} from './TabsContext'; | ||
import {getElementName} from './utils'; | ||
|
||
export interface TabPanelsProps { | ||
children: React.ReactNode; | ||
element?: BoxProps['element']; | ||
} | ||
|
||
const TabPanels = React.forwardRef<HTMLDivElement, TabPanelsProps>(({children, ...props}, ref) => { | ||
const TabPanels = React.forwardRef<HTMLDivElement, TabPanelsProps>(({children, element, ...props}, ref) => { | ||
const {orientation} = React.useContext(TabsContext); | ||
const elementName = getElementName(orientation, 'TAB_PANELS', element); | ||
return ( | ||
<Box {...safelySpreadBoxProps(props)} width="100%" ref={ref}> | ||
<Box {...safelySpreadBoxProps(props)} element={elementName} width="100%" ref={ref}> | ||
{children} | ||
</Box> | ||
); | ||
}); | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
TabPanels.propTypes = { | ||
element: PropTypes.string, | ||
}; | ||
} | ||
|
||
TabPanels.displayName = 'TabPanels'; | ||
export {TabPanels}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import * as React from 'react'; | ||
import {TabPrimitiveState} from '@twilio-paste/tabs-primitive'; | ||
import {Variants} from './types'; | ||
import type {TabPrimitiveState} from '@twilio-paste/tabs-primitive'; | ||
import type {Variants} from './types'; | ||
|
||
interface TabState extends TabPrimitiveState { | ||
interface TabState extends Omit<TabPrimitiveState, 'orientation'> { | ||
variant?: Variants; | ||
orientation: 'horizontal' | 'vertical'; | ||
} | ||
|
||
const TabsContext = React.createContext<Partial<TabState>>({}); | ||
const TabsContext = React.createContext<TabState>({} as TabState); | ||
|
||
export {TabsContext}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getElementName = ( | ||
orientation: 'horizontal' | 'vertical', | ||
fallback: string, | ||
elementName?: string | undefined | ||
): string => (elementName != null ? elementName : `${orientation.toUpperCase()}_${fallback}`); |
Oops, something went wrong.