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

♻️ Rewrite Dialog stories in Typescript #752

Merged
merged 7 commits into from
Nov 5, 2020
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
195 changes: 0 additions & 195 deletions apps/storybook-react/stories/Dialog.stories.jsx

This file was deleted.

178 changes: 178 additions & 0 deletions apps/storybook-react/stories/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import React, { Fragment, useState } from 'react'
import {
Dialog,
DialogProps,
Button,
Scrim,
Typography,
} from '@equinor/eds-core-react'
import styled from 'styled-components'
import { Story, Meta } from '@storybook/react/types-6-0'

const { Actions, Title, CustomContent } = Dialog

export default {
title: 'Components/Dialog',
component: Dialog,
subcomponents: { Actions, Title, CustomContent },
parameters: {
docs: {
description: {
component: `A basic dialog component`,
},
},
},
} as Meta

const Body = styled.div`
height: 200px;
background: #ebebeb;
display: grid;
grid-template-rows: 1fr auto 1fr;
padding: 32px;
grid-gap: 32px;
position: relative;
`

const TempButtonWrapper = styled.div`
display: grid;
column-gap: 16px;
grid-template-columns: repeat(2, fit-content(100%));
justify-content: end;
justify-self: end;
`

const Placeholder = styled.div`
background: rgba(255, 146, 0, 0.15);
border: 1px dashed #ff9200;
box-sizing: border-box;
border-radius: 4px;
padding: 8px;
width: 100%;
display: inline-block;
`

const TITLE_CHOICES = {
none: null,
text: 'Title',
}

const CUSTOM_CONTENT_CHOICES = {
none: null,
empty: <Placeholder>Custom content</Placeholder>,
emptyLarge: (
<Placeholder>
Custom content in a larger placeholder. No actions, only ESC or timedelay?
Test testestsetsest
</Placeholder>
),
description: (
<Typography variant="body_short">Small description here.</Typography>
),
scroll: (
<Fragment>
<Typography variant="body_short">
Lorem ipsum dolor sit amet consecteur dit lot. Lorem ipsum dolor sit
amet consecteur dit lot. Lorem ipsum dolor sit amet consecteur dit lot.{' '}
</Typography>
<Typography variant="body_short">
Lorem ipsum dolor sit amet consecteur dit lot. Lorem ipsum dolor sit
amet consecteur dit lot. Lorem ipsum dolor sit amet consecteur dit lot.{' '}
</Typography>
</Fragment>
),
}

const ACTION_CHOICES = {
none: null,
buttons: (
<TempButtonWrapper>
<Button>OK</Button>
<Button variant="ghost">Cancel</Button>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok left, cancel right…

</TempButtonWrapper>
),
}

export const Default: Story<DialogProps> = () => (
<Dialog>
<Title>{TITLE_CHOICES['text']}</Title>
<CustomContent>{CUSTOM_CONTENT_CHOICES['description']}</CustomContent>
<Actions>
<TempButtonWrapper>
<Button>OK</Button>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancel left, OK right… 🤔 I think this has gone unnoticed in the original story…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So affirmative actions always on the left, destructive actions on the right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not the other way around? 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from Figma, but I don’t know who made that in Figma. Maybe there’s something in the Storefront…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that this is correct

<Button>Cancel</Button>
</TempButtonWrapper>
</Actions>
</Dialog>
)

export const WithScrim: Story<DialogProps> = () => {
const [visibleScrim, setVisibleScrim] = useState(false)
const handleClose = () => {
setVisibleScrim(!visibleScrim)
}
return (
<Body>
<div>
<Button onClick={() => setVisibleScrim(true)}>Trigger Dialog</Button>
</div>
{visibleScrim && (
<Scrim onClose={handleClose}>
<Dialog>
<Title>{TITLE_CHOICES['text']}</Title>
<CustomContent scrollable>
{CUSTOM_CONTENT_CHOICES['scroll']}
</CustomContent>
<Actions>
<TempButtonWrapper>
<Button variant="ghost" onClick={() => setVisibleScrim(false)}>
Cancel
</Button>
<Button onClick={() => setVisibleScrim(false)}>OK</Button>
</TempButtonWrapper>
</Actions>
</Dialog>
</Scrim>
)}
</Body>
)
}

export const TextPlusAction: Story<DialogProps> = () => (
<Dialog>
<Title>Text + actions</Title>
<CustomContent>{CUSTOM_CONTENT_CHOICES['description']}</CustomContent>
<Actions>{ACTION_CHOICES['buttons']}</Actions>
</Dialog>
)

export const PlaceholderPlusAction: Story<DialogProps> = () => (
<Dialog>
<Title>Placeholder + actions</Title>
<CustomContent>{CUSTOM_CONTENT_CHOICES['empty']}</CustomContent>
<Actions>{ACTION_CHOICES['buttons']}</Actions>
</Dialog>
)

export const PlaceholderOnly: Story<DialogProps> = () => (
<Dialog>
<Title>Placeholder</Title>
<CustomContent>{CUSTOM_CONTENT_CHOICES['emptyLarge']}</CustomContent>
<Actions>{ACTION_CHOICES['none']}</Actions>
</Dialog>
)

export const ScrollablePlusActions: Story<DialogProps> = () => (
<Dialog>
<Title>Scrollable + actions</Title>
<CustomContent scrollable>{CUSTOM_CONTENT_CHOICES['scroll']}</CustomContent>
<Actions>{ACTION_CHOICES['buttons']}</Actions>
</Dialog>
)

export const NoTitle: Story<DialogProps> = () => (
<Dialog>
<CustomContent>{CUSTOM_CONTENT_CHOICES['description']}</CustomContent>
<Actions>{ACTION_CHOICES['buttons']}</Actions>
</Dialog>
)
Loading