Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RelativeTime stories #3136

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -3438,7 +3438,7 @@
"stories": [
{
"id": "components-relativetime--default",
"code": "(args) => {\n const { date, ...rest } = args\n return <RelativeTime {...rest} date={new Date(date)} />\n}"
"code": "() => <RelativeTime date={new Date('2020-01-01T00:00:00Z')} />"
}
],
"props": [
Expand Down
155 changes: 155 additions & 0 deletions src/RelativeTime/RelativeTime.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import RelativeTime from './RelativeTime'
import React from 'react'
import {Meta, Story} from '@storybook/react'

const meta: Meta = {
title: 'Components/RelativeTime/Features',
component: RelativeTime,
parameters: {
layout: 'fullscreen',
controls: {
// StoryBook infers from type info of the component which includes CE Lifecycle,
// SX props, and methods we want to otherwise ignore
exclude: /^(getFormatted.*|datetime|sx|as|theme|forwardedAs|.*Callback|update)$/g,
},
// it's not possible to snapshot test relative time because the output keeps changing
chromatic: {disableSnapshot: true},
},
args: {
date: new Date('2020-01-01T00:00:00Z'),
second: '',
minute: '',
hour: '',
weekday: '',
day: 'numeric',
month: 'short',
year: '',
timeZoneName: '',
},
argTypes: {
hour: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
minute: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
second: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
weekday: {
type: {
name: 'enum',
value: ['', 'short', 'long', 'narrow'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
day: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
month: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit', 'long', 'short', 'narrow'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
year: {
type: {
name: 'enum',
value: ['', 'numeric', '2-digit'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
timeZoneName: {
type: {
name: 'enum',
value: ['', 'long', 'short', 'longOffset', 'shortOffset', 'longGeneric', 'shortGeneric'],
},
control: {
type: 'select',
labels: {
'': '(None)',
},
},
},
date: {
control: 'date',
},
format: {
control: 'string',
},
},
}

export const MicroFormat: Story = args => {
const {date, ...rest} = args
return <RelativeTime {...rest} date={new Date(date)} format="micro" />
}
MicroFormat.args = {tense: 'past'}
MicroFormat.argTypes = {format: {control: false}}

export const RecentTime: Story = args => {
const {...rest} = args
return <RelativeTime {...rest} date={new Date()} />
}
RecentTime.argTypes = {date: {control: false}}

export const CountDownTimer: Story = args => {
const {...rest} = args
return <RelativeTime {...rest} />
}
CountDownTimer.args = {date: new Date('2038-01-19T03:14:08Z'), format: 'elapsed', day: '', month: ''}
CountDownTimer.argTypes = {date: {control: false}, format: {control: false}}

export default meta
Loading