-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
d8243c9
commit eea6df0
Showing
16 changed files
with
260 additions
and
5 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
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,25 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Stepper, StepperProps } from './Stepper'; | ||
|
||
import { StepperItem } from '.'; | ||
|
||
const Render = (args: any) => ( | ||
<Stepper aria-label='Example Stepper' {...args}> | ||
<StepperItem textValue='1' /> | ||
<StepperItem textValue='2' /> | ||
<StepperItem textValue='3' /> | ||
</Stepper> | ||
); | ||
|
||
export default { | ||
title: 'Status/Stepper', | ||
component: Stepper, | ||
render: Render | ||
} as Meta<typeof Stepper>; | ||
|
||
export const Default: StoryObj<StepperProps> = { | ||
args: { | ||
index: 1 | ||
} | ||
}; |
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,26 @@ | ||
import styled, { css } from 'styled-components'; | ||
|
||
import { Divider } from '../Divider'; | ||
import { Flex } from '../Flex'; | ||
|
||
type StyledStepProps = { | ||
$status: 'incomplete' | 'complete' | 'active'; | ||
}; | ||
|
||
const StyledStep = styled(Flex)<StyledStepProps>` | ||
${({ theme, $status }) => css` | ||
${theme.stepper.step.base} | ||
${theme.stepper.step[$status]} | ||
`} | ||
`; | ||
|
||
const StyledDivider = styled(Divider)<StyledStepProps>` | ||
width: 100%; | ||
align-self: auto; | ||
flex: 1 1 0%; | ||
${({ theme, $status }) => css` | ||
${theme.stepper.divider[$status]} | ||
`} | ||
`; | ||
|
||
export { StyledStep, StyledDivider }; |
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,41 @@ | ||
import { forwardRef } from 'react'; | ||
import { Selection } from '@react-types/shared'; | ||
import { useCollection } from '@react-stately/collections'; | ||
import { ListCollection } from '@react-stately/list'; | ||
|
||
import { Flex, FlexProps } from '../Flex'; | ||
|
||
import { StepperItem } from './StepperItem'; | ||
|
||
type Props = { | ||
index?: number; | ||
fullWidth?: boolean; | ||
}; | ||
|
||
type NativeAttrs = Omit<FlexProps, keyof Props | 'direction'>; | ||
|
||
type StepperProps = Props & NativeAttrs; | ||
|
||
const Stepper = forwardRef<HTMLDivElement, StepperProps>(({ index = 0, ...props }, ref): JSX.Element => { | ||
const collection = useCollection(props as any, (nodes) => new ListCollection(nodes) as any); | ||
|
||
const steps = [...collection]; | ||
|
||
return ( | ||
<Flex ref={ref} direction='row' gap='xl' {...props}> | ||
{steps.map((item, idx) => ( | ||
<StepperItem | ||
key={item.key} | ||
isLast={steps.length - 1 === idx} | ||
item={item} | ||
status={idx > index ? 'incomplete' : idx === index ? 'active' : 'complete'} | ||
/> | ||
))} | ||
</Flex> | ||
); | ||
}); | ||
|
||
Stepper.displayName = 'Stepper'; | ||
|
||
export { Stepper }; | ||
export type { StepperProps, Selection }; |
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,34 @@ | ||
import { Node } from '@react-types/shared'; | ||
|
||
import { Span } from '../Text'; | ||
import { Flex, FlexProps } from '../Flex'; | ||
|
||
import { StyledDivider, StyledStep } from './Stepper.style'; | ||
|
||
type Props = {}; | ||
|
||
type InheritAttrs = Omit<FlexProps, keyof Props>; | ||
|
||
type StepperItemProps = Props & InheritAttrs; | ||
|
||
type InternalProps<T extends object> = StepperItemProps & { | ||
item: Node<T>; | ||
status: 'active' | 'complete' | 'incomplete'; | ||
isLast: boolean; | ||
fullWidth?: boolean; | ||
}; | ||
|
||
const StepperItem = <T extends object>({ status, isLast, item }: InternalProps<T>): JSX.Element => ( | ||
<Flex alignItems='center' flex={isLast ? 'initial' : '1 1 0%'} gap='xl'> | ||
<Flex alignItems='center' gap='md' justifyContent='center'> | ||
<StyledStep $status={status} alignItems='center' justifyContent='center'> | ||
<Span weight='bold'>{(item.index || 0) + 1}</Span> | ||
</StyledStep> | ||
{item.rendered} | ||
</Flex> | ||
{!isLast && <StyledDivider $status={status} size='md' />} | ||
</Flex> | ||
); | ||
|
||
export { StepperItem }; | ||
export type { StepperItemProps }; |
36 changes: 36 additions & 0 deletions
36
packages/components/src/Stepper/__tests__/Stepper.test.tsx
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,36 @@ | ||
import { createRef } from 'react'; | ||
import { testA11y, render } from '@interlay/test-utils'; | ||
|
||
import { Stepper, StepperItem } from '..'; | ||
|
||
describe('Stepper', () => { | ||
it('should render correctly', () => { | ||
const wrapper = render( | ||
<Stepper aria-label='progress'> | ||
<StepperItem>item</StepperItem> | ||
</Stepper> | ||
); | ||
|
||
expect(() => wrapper.unmount()).not.toThrow(); | ||
}); | ||
|
||
it('ref should be forwarded', () => { | ||
const ref = createRef<HTMLDivElement>(); | ||
|
||
render( | ||
<Stepper ref={ref} aria-label='progress'> | ||
<StepperItem>item</StepperItem> | ||
</Stepper> | ||
); | ||
|
||
expect(ref.current).not.toBeNull(); | ||
}); | ||
|
||
it('should pass a11y', async () => { | ||
await testA11y( | ||
<Stepper aria-label='progress'> | ||
<StepperItem>item</StepperItem> | ||
</Stepper> | ||
); | ||
}); | ||
}); |
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,15 @@ | ||
import { Item } from '@react-stately/collections'; | ||
import { ItemProps } from '@react-types/shared'; | ||
import { ReactNode } from 'react'; | ||
|
||
import { StepperItemProps } from './StepperItem'; | ||
|
||
const StepperItem = Item as <T>( | ||
props: Omit<ItemProps<T>, 'children'> & StepperItemProps & { children?: ReactNode } | ||
) => JSX.Element; | ||
|
||
export type { StepperProps, Selection } from './Stepper'; | ||
export { Stepper } from './Stepper'; | ||
|
||
export type { StepperItemProps }; | ||
export { StepperItem }; |
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,17 @@ | ||
import { StyledObject } from 'styled-components'; | ||
|
||
type StepperTheme = { | ||
step: { | ||
base: StyledObject<object>; | ||
active: StyledObject<object>; | ||
incomplete: StyledObject<object>; | ||
complete: StyledObject<object>; | ||
}; | ||
divider: { | ||
active: StyledObject<object>; | ||
incomplete: StyledObject<object>; | ||
complete: StyledObject<object>; | ||
}; | ||
}; | ||
|
||
export type { StepperTheme }; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { rounded, spacing } from '../../core'; | ||
import { StepperTheme } from '../../components'; | ||
|
||
import { color } from './colors'; | ||
|
||
const stepper: StepperTheme = { | ||
divider: { | ||
incomplete: { | ||
backgroundColor: color('grey-400') | ||
}, | ||
active: { | ||
backgroundColor: color('grey-400') | ||
}, | ||
complete: { | ||
backgroundColor: color('primary-500') | ||
} | ||
}, | ||
step: { | ||
base: { | ||
width: spacing('5xl'), | ||
height: spacing('5xl'), | ||
borderRadius: rounded('full'), | ||
color: color('light'), | ||
borderWidth: '2px', | ||
borderStyle: 'solid', | ||
backgroundColor: color('grey-700') | ||
}, | ||
active: { | ||
borderColor: color('primary-500') | ||
}, | ||
incomplete: { | ||
borderColor: color('grey-400') | ||
}, | ||
complete: { | ||
borderColor: color('primary-500'), | ||
backgroundColor: color('primary-500') | ||
} | ||
} | ||
}; | ||
|
||
export { stepper }; |