-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SELF-243: Add Steps Component (#472)
* feat: add icon button * feat: add steps component * refactor: Ken PR review
- Loading branch information
1 parent
c90549a
commit d24c4bd
Showing
27 changed files
with
329 additions
and
103 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,10 @@ | ||
import { Canvas, ArgTypes, PRIMARY_STORY } from '@storybook/addon-docs'; | ||
import { Primary } from './Steps.stories'; | ||
|
||
# Steps | ||
|
||
<Canvas of={Primary} /> | ||
|
||
## Props | ||
|
||
<ArgTypes story={PRIMARY_STORY} /> |
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 { Meta, StoryObj } from '@storybook/vue3'; | ||
import mdx from './Steps.mdx'; | ||
// @ts-ignore No types from Vue file | ||
import Steps from './Steps.vue'; | ||
|
||
const meta: Meta<typeof Steps> = { | ||
title: 'Components/Steps', | ||
component: Steps, | ||
parameters: { | ||
docs: { | ||
page: mdx | ||
} | ||
} | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Primary: StoryObj<typeof Steps> = { | ||
args: { | ||
items: [ | ||
{ label: 'Step 1', status: 'success' }, | ||
{ label: 'Step 2' }, | ||
{ label: 'Step 3' } | ||
] | ||
} | ||
}; |
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,119 @@ | ||
<template> | ||
<Steps | ||
v-model:activeStep="activeStep" | ||
:model="primeVueItems" | ||
:pt="{ menu: { class: 'uic-steps-menu' } }" | ||
:readonly="false" | ||
data-testid="uic-steps" | ||
> | ||
<template #item="{ active, index, label }"> | ||
<span :class="['uic-steps-action', { active }]"> | ||
<span :class="['uic-steps-step', { icon: Boolean(stepIcons[index]) }]"> | ||
<Icon | ||
v-if="stepIcons[index]" | ||
:icon="stepIcons[index]" | ||
data-testid="uic-steps-icon" | ||
/> | ||
<template v-else> | ||
{{ index + 1 }} | ||
</template> | ||
</span> | ||
<span class="uic-steps-label">{{ label }}</span> | ||
<Transition> | ||
<span v-if="active" class="uic-steps-active-indicator" /> | ||
</Transition> | ||
</span> | ||
</template> | ||
</Steps> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Steps, { StepsProps } from 'primevue/steps'; | ||
import { computed, defineModel } from 'vue'; | ||
import { Icon, IconName } from '../Icon'; | ||
import { StepItem } from './types'; | ||
const props = withDefaults( | ||
defineProps<{ | ||
items: StepItem[]; | ||
readonly?: boolean; | ||
}>(), | ||
{ | ||
readonly: false | ||
} | ||
); | ||
const activeStep = defineModel<number>('activeStep', { default: 0 }); | ||
const primeVueItems = computed<StepsProps['model']>(() => { | ||
return props.items.map((item) => ({ | ||
label: item.label | ||
})); | ||
}); | ||
const stepIcons = computed<Record<number, IconName>>(() => { | ||
const icons: Record<number, IconName> = {}; | ||
props.items.forEach((item, index) => { | ||
if (item.status === 'success') { | ||
icons[index] = IconName.SUCCESS; | ||
} | ||
}); | ||
return icons; | ||
}); | ||
</script> | ||
|
||
<style lang="scss"> | ||
.uic-steps-menu { | ||
@apply flex gap-12; | ||
} | ||
.uic-steps-action { | ||
@apply relative; | ||
@apply cursor-pointer; | ||
@apply flex gap-2 items-center; | ||
@apply py-4; | ||
} | ||
.uic-steps-label { | ||
@apply type-small-600 text-gray-600; | ||
@apply transition-colors; | ||
.active & { | ||
@apply text-upgrade; | ||
} | ||
} | ||
.uic-steps-step { | ||
@apply flex items-center justify-center; | ||
@apply w-5 h-5 rounded-full; | ||
@apply bg-gray-50; | ||
@apply type-xs-600 text-gray-600; | ||
@apply transition-colors; | ||
.active & { | ||
@apply bg-transparent; | ||
@apply border border-upgrade; | ||
@apply text-upgrade; | ||
} | ||
&.icon { | ||
@apply bg-upgrade; | ||
@apply text-white; | ||
@apply border-none; | ||
} | ||
} | ||
.uic-steps-active-indicator { | ||
@apply absolute bottom-0 left-0 right-0; | ||
@apply bg-upgrade h-[2px]; | ||
&.v-enter-active, | ||
&.v-leave-active { | ||
transition: opacity 0.25s ease-in-out; | ||
} | ||
&.v-enter-from, | ||
&.v-leave-to { | ||
opacity: 0; | ||
} | ||
} | ||
</style> |
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,42 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, within } from '@testing-library/vue'; | ||
|
||
import Steps from '../Steps.vue'; | ||
|
||
type PropsType = InstanceType<typeof Steps>['$props']; | ||
|
||
const DEFAULT_PROPS: PropsType = { | ||
items: [{ label: 'Step 1' }, { label: 'Step 2' }, { label: 'Step 3' }] | ||
}; | ||
|
||
describe('Steps', () => { | ||
let props: PropsType; | ||
|
||
beforeEach(() => { | ||
props = { ...DEFAULT_PROPS }; | ||
}); | ||
|
||
it('renders', () => { | ||
const { getByTestId } = render(Steps, { props }); | ||
|
||
const steps = getByTestId('uic-steps'); | ||
expect(steps).toBeVisible(); | ||
const { getByText: stepsGetByText } = within(steps); | ||
expect(stepsGetByText('Step 1')).toBeVisible(); | ||
expect(stepsGetByText('Step 2')).toBeVisible(); | ||
expect(stepsGetByText('Step 3')).toBeVisible(); | ||
}); | ||
|
||
it('renders icons with statuses', async () => { | ||
props = { | ||
...props, | ||
items: [ | ||
{ label: 'Step 1', status: 'success' }, | ||
{ label: 'Step 2' }, | ||
{ label: 'Step 3' } | ||
] | ||
}; | ||
const { findByTestId } = render(Steps, { props }); | ||
expect(await findByTestId('uic-steps-icon')).toBeVisible(); | ||
}); | ||
}); |
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,4 @@ | ||
export const StepsStatus = { | ||
SUCCESS: 'success' | ||
} as const; | ||
export type StepsStatus = (typeof StepsStatus)[keyof typeof StepsStatus]; |
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,3 @@ | ||
export * from './constants'; | ||
export { default as Steps } from './Steps.vue'; | ||
export * from './types'; |
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 @@ | ||
import { StepsStatus } from './constants'; | ||
|
||
export interface StepItem { | ||
label: string; | ||
status?: StepsStatus; | ||
} |
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
Oops, something went wrong.