UNPKG

@workday/canvas-kit-labs-react

Version:

Canvas Kit Labs is an incubator for new and experimental components. Since we have a rather rigorous process for getting components in at a production level, it can be valuable to make them available earlier while we continuously iterate on the API/functi

26 lines (25 loc) 1.13 kB
import React from 'react'; import { createSubcomponent, focusRing, styled, } from '@workday/canvas-kit-react/common'; import { Flex } from '@workday/canvas-kit-react/layout'; import { colors } from '@workday/canvas-kit-react/tokens'; import { useExpandableTarget } from './hooks/useExpandableTarget'; import { useExpandableModel } from './hooks/useExpandableModel'; const StyledButton = styled(Flex.as('button'))({ cursor: 'pointer', '&:focus-visible, &.focus': { ...focusRing(), }, '&:hover': { background: colors.soap300, }, }); const Heading = styled('h1')({ margin: 0, }); export const ExpandableTarget = createSubcomponent('button')({ modelHook: useExpandableModel, elemPropsHook: useExpandableTarget, })(({ children, headingLevel, ...elementProps }, Element) => { const button = (React.createElement(StyledButton, { as: Element, background: "none", border: "none", borderRadius: "m", flexDirection: "row", padding: "xxs", width: "100%", ...elementProps }, children)); return !!headingLevel ? React.createElement(Heading, { as: headingLevel }, button) : button; });