-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Seedy
authored
Jan 25, 2022
1 parent
e406462
commit 099c10c
Showing
6 changed files
with
104 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { RadioAccordionRoot, RadioAccordionItem, RadioAccordionContent, RadioAccordionTrigger } from './RadioAccordion'; | ||
import { Box } from '../Box'; | ||
|
||
export default { | ||
title: 'Components/RadioAccordion', | ||
component: RadioAccordionRoot, | ||
} as ComponentMeta<typeof RadioAccordionRoot>; | ||
|
||
export const Basic: ComponentStory<typeof RadioAccordionRoot> = (args) => ( | ||
<Box css={{ width: 300 }}> | ||
<RadioAccordionRoot {...args}> | ||
<RadioAccordionItem value="item-1"> | ||
<RadioAccordionTrigger >Item1 Trigger</RadioAccordionTrigger> | ||
<RadioAccordionContent >Item1 Content</RadioAccordionContent> | ||
</RadioAccordionItem> | ||
<RadioAccordionItem value="item-2"> | ||
<RadioAccordionTrigger >Item2 Trigger</RadioAccordionTrigger> | ||
<RadioAccordionContent >Item2 Content</RadioAccordionContent> | ||
</RadioAccordionItem> | ||
<RadioAccordionItem value="item-3"> | ||
<RadioAccordionTrigger >Item3 Trigger</RadioAccordionTrigger> | ||
<RadioAccordionContent >Item3 Content</RadioAccordionContent> | ||
</RadioAccordionItem> | ||
</RadioAccordionRoot> | ||
</Box> | ||
); |
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,62 @@ | ||
import React, { ComponentProps } from "react"; | ||
import { styled, VariantProps } from "../../stitches.config"; | ||
import { StyledAccordionTrigger, StyledAccordionHeader, AccordionRoot, AccordionContent, AccordionItem, AccordionTriggerProps } from "../Accordion"; | ||
import { INDICATOR_BASE_STYLES, RADIO_BASE_STYLES } from "../Radio"; | ||
|
||
type RadioAccordionRootProps = Omit<VariantProps<typeof AccordionRoot>, 'type'> | ||
export const RadioAccordionRoot: (props: RadioAccordionRootProps) => JSX.Element = (props) => ( | ||
<AccordionRoot {...props} type='single' collapsible={false} /> | ||
) | ||
export const RadioAccordionItem = React.forwardRef<React.ElementRef<typeof AccordionItem>, ComponentProps<typeof AccordionItem>>(({ value, children, ...props }, forwardedRef) => { | ||
|
||
return ( | ||
<AccordionItem value={value} ref={forwardedRef} css={{ display: 'inherit', flexDirection: 'column' } as any} {...props}> | ||
{children} | ||
</AccordionItem> | ||
); | ||
}); | ||
|
||
const StyledRadio = styled('div', RADIO_BASE_STYLES, { | ||
width: 18, | ||
height: 18, | ||
mr: '$2', | ||
}) | ||
|
||
const StyledIndicator = styled('div', INDICATOR_BASE_STYLES, { | ||
'&::after': { | ||
'[data-state=open] &': { | ||
backgroundColor: '$radioIndicator' | ||
}, | ||
'[data-state=closed] &': { | ||
backgroundColor: 'transparent', | ||
} | ||
}, | ||
}); | ||
|
||
const StyledRadioAccordionTrigger = styled(StyledAccordionTrigger, { | ||
'@hover': { | ||
'&:hover': { | ||
[`& ${StyledRadio}`]: { | ||
boxShadow: 'inset 0 0 0 1px $colors$radioHoverBorder', | ||
backgroundColor: '$radioHoverBg', | ||
} | ||
} | ||
} | ||
}) | ||
|
||
export const RadioAccordionTrigger = React.forwardRef< | ||
React.ElementRef<typeof StyledRadioAccordionTrigger>, AccordionTriggerProps>(({ children, ...props }, ref) => { | ||
|
||
return ( | ||
<StyledAccordionHeader> | ||
<StyledRadioAccordionTrigger ref={ref} {...props}> | ||
<StyledRadio > | ||
<StyledIndicator /> | ||
</StyledRadio> | ||
{children} | ||
</StyledRadioAccordionTrigger> | ||
</StyledAccordionHeader> | ||
) | ||
}) | ||
|
||
export const RadioAccordionContent = AccordionContent |
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 @@ | ||
export * from './RadioAccordion'; |
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