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

feat(dialog): adding styles for native dialog #2772

Merged
merged 35 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4351f35
feat(dialog): adds styling and docs
gfellerph Feb 29, 2024
bf3c120
Merge branch 'main' into 1536-component-dialog
gfellerph Mar 1, 2024
3fe243d
refactor: animations and dialog part names
gfellerph Mar 7, 2024
d5f4a45
Merge branch 'main' into 1536-component-dialog
gfellerph Mar 7, 2024
f332c67
Merge branch 'main' into 1536-component-dialog
gfellerph Mar 20, 2024
c9a03db
chore: deprecating modal and notification overlay
gfellerph Mar 21, 2024
f796576
chore: add changesets
gfellerph Mar 21, 2024
f29cf71
chore: added code samples
gfellerph Mar 21, 2024
1dfcead
chore: fix styles typo
gfellerph Mar 21, 2024
e701651
Merge branch 'main' into 1536-component-dialog
gfellerph Apr 12, 2024
b19cd2f
refactor: split dialog up into variants
gfellerph Apr 15, 2024
f1cca20
Merge branch 'main' into 1536-component-dialog
gfellerph May 1, 2024
bc6c902
Merge branch 'main' into 1536-component-dialog
gfellerph May 29, 2024
49b3875
fix: animations
gfellerph May 29, 2024
534d53e
Merge branch 'main' into 1536-component-dialog
gfellerph Jul 23, 2024
ca07cd6
Merge branch 'main' into 1536-component-dialog
gfellerph Aug 9, 2024
beed725
chore: clean up and scope down to just dialog
gfellerph Aug 9, 2024
f023e4f
chore: deprecate notification without replacement
gfellerph Aug 9, 2024
fd8c570
fix: linting
gfellerph Aug 9, 2024
dac7bb5
fix: disable this behavior, does not work with non-modal dialogs
gfellerph Aug 9, 2024
e305176
chore: add snapshot tests
gfellerph Aug 9, 2024
5da958c
fix: linting errors
gfellerph Aug 9, 2024
1d85c6e
Merge branch 'main' into 1536-component-dialog
gfellerph Aug 15, 2024
881cae5
Update .changeset/popular-games-rush.md
gfellerph Sep 10, 2024
cadcfcb
Update packages/documentation/package.json
gfellerph Sep 10, 2024
3e18775
Update packages/documentation/src/stories/components/dialog/dialog.do…
gfellerph Sep 10, 2024
86a987c
Update packages/documentation/src/stories/components/dialog/dialog.do…
gfellerph Sep 10, 2024
f91aef5
Merge branch 'main' into 1536-component-dialog
gfellerph Sep 10, 2024
159a291
Apply suggestions from code review
gfellerph Sep 10, 2024
5017cf8
Merge branch '1536-component-dialog' of https://github.com/swisspost/…
gfellerph Sep 10, 2024
55b3f02
update docs and styles to use classes instead of custom elements
gfellerph Sep 10, 2024
8f38ff7
removed angular form data example
gfellerph Sep 10, 2024
e163bfa
Merge branch 'main' into 1536-component-dialog
gfellerph Oct 7, 2024
df30dca
chore: fix dialog display
gfellerph Oct 7, 2024
3021bb0
revert margins for the dialog
gfellerph Oct 8, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Canvas, Controls, Meta } from '@storybook/blocks';
import * as DialogStories from './dialog.stories';

<Meta of={DialogStories} />

# Dialog
gfellerph marked this conversation as resolved.
Show resolved Hide resolved

<Canvas sourceState="shown" of={DialogStories.Default} />
<div className="hide-col-default">
<Controls of={DialogStories.Default} />
</div>

gfellerph marked this conversation as resolved.
Show resolved Hide resolved
## Form dialog
gfellerph marked this conversation as resolved.
Show resolved Hide resolved
<Canvas sourceState="hidden" of={DialogStories.Form} />

## Cookie banner
<Canvas sourceState="hidden" of={DialogStories.Cookie} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import { BADGE } from '@geometricpanda/storybook-addon-badges';
import { background } from '@storybook/theming';
import { Args, Meta, StoryObj } from '@storybook/web-components';
import { TemplateResult, html, nothing } from 'lit-html';

const meta: Meta = {
id: '562eac2b-6dc1-4007-ba8e-4e981cef0cbc',
title: 'Components/Dialog',
parameters: {
badges: [BADGE.NEEDS_REVISION],
design: {
type: 'figma',
gfellerph marked this conversation as resolved.
Show resolved Hide resolved
},
},
args: {
variant: 'standard',
notificationType: 'general',
title: 'Dialog',
content: 'This is a dialog',
size: 'medium',
open: true,
closeButton: true,
},
argTypes: {
variant: {
name: 'Variant',
description: 'Choose which dialog variant to display',
control: 'radio',
options: ['standard', 'notification', 'cookie'],
table: { category: 'Variant' },
},
notificationType: {
name: 'Notification type',
description: 'Choose the type of notification to display',
control: 'select',
options: ['general', 'error', 'warning', 'success', 'brand'],
if: {
arg: 'variant',
eq: 'notification',
},
table: { category: 'Variant' },
},
title: {
name: 'Title',
description: 'Optional title',
control: 'text',
table: { category: 'Content' },
},
content: {
name: 'Content',
description: 'Dialog text',
control: 'text',
table: { category: 'Content' },
},
size: {
name: 'Size',
description: 'Max width of the dialog.',
control: {
type: 'select',
},
options: ['small', 'medium', 'large'],
table: { category: 'Variant' },
},
closeButton: {
name: 'Close button',
description: 'Show a close button to dismiss the dialog',
control: 'boolean',
table: { category: 'Content' },
},
},
decorators: [
(story: Function) =>
html`<div>
<button
id="show-dialog-button"
class="btn btn-secondary"
onclick="this.nextElementSibling.showModal()"
>
Show dialog</button
>${story()}
</div>`,
],
};

export default meta;

const notificationTypeIconMap: { [key: string]: { icon: number; color: string } } = {
general: { icon: 1034, color: 'bg-info' },
error: { icon: 2104, color: 'bg-danger' },
warning: { icon: 2106, color: 'bg-warning' },
success: { icon: 2105, color: 'bg-success' },
brand: { icon: 1034, color: 'bg-yellow' },
};

const getHeader = (text: string) => {
return html`<h2>${text}</h2>`;
};

const getCloseButton = () => {
return html`<button class="btn btn-close">
<span class="visually-hidden">Close</span>
</button>`;
};

const getControls = () => {
return html`<button class="btn btn-primary">OK</button>
<button class="btn btn-secondary">Cancel</button>`;
};

const Template = {
render: (args: Args) => {
let variant = nothing;
let notificationType: symbol | string = nothing;
let backgroundColor: string | symbol = nothing;

let icon: symbol | TemplateResult = nothing;
let header = getHeader(args.title);
let body = html`${args.content}`;
const controls = getControls();
const closeButton = args.closeButton ? getCloseButton() : nothing;

if (args.variant === 'notification') {
variant = args.variant;
const { icon: iconNr } = notificationTypeIconMap[args.notificationType];
notificationType = args.notificationType as string;
icon = html`<post-icon name="${iconNr}"></post-icon>`;
header = getHeader(args.title);
}
if (args.variant === 'cookie') {
backgroundColor = 'bg-light';
icon = html`<post-icon name="2201"></post-icon>`;
variant = args.variant;
}
return html`
<dialog
data-size="${args.size}"
data-variant="${variant}"
data-type="${notificationType}"
class="${backgroundColor}"
>
<form method="dialog">
<post-dialog-icon>${icon}</post-dialog-icon>
<post-dialog-header>${header}</post-dialog-header>
alizedebray marked this conversation as resolved.
Show resolved Hide resolved
<post-dialog-body>${body}</post-dialog-body>
<post-dialog-controls>${controls}</post-dialog-controls>
${args.closeButton
? html`<post-dialog-close>${closeButton}</post-dialog-close>`
: nothing}
</form>
</dialog>
`;
},
};

const FormTemplate = {
render: (args: Args) => {
return html`
<dialog size="${args.size}">
<form method="dialog">
<h3>Form example</h3>
<div class="form-floating mt-3">
<input
id="ExampleTextarea_Default"
class="form-control form-control-lg"
type="text"
placeholder="Placeholder"
/>
<label class="form-label" for="ExampleTextarea_Default">Label</label>
<div class="form-text">
Hintus textus elare volare cantare hendrerit in vulputate velit esse molestie
consequat, vel illum dolore eu feugiat nulla facilisis.
</div>
</div>
<div class="dialog-controls">
<button class="btn btn-primary">Confirm</button>
<button class="btn btn-secondary" formnovalidate>Cancel</button>
</div>
</form>
</dialog>
`;
},
};

const CookieTemplate = {
...Template,
args: {
variant: 'cookie',
closeButton: false,
size: 'large',
},
};

type Story = StoryObj;

export const Default: Story = {
...Template,
};

export const Form: Story = {
...FormTemplate,
};

export const Cookie: Story = {
...CookieTemplate,
};
1 change: 1 addition & 0 deletions packages/styles/src/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@use 'form-select';
@use 'form-textarea';
@use 'datatable';
@use 'dialog';
@use 'form-check';
@use 'forms';
@use 'grid';
Expand Down
Loading
Loading