-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
184 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Toast } from './Toast'; | ||
|
||
const meta = { | ||
title: 'Snackbars/Toast', | ||
component: Toast, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof Toast>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Icon: Story = { | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?node-id=542%3A8376', | ||
}, | ||
docs: { | ||
description: { | ||
story: 'This is a toast component for displaying a text.', | ||
}, | ||
}, | ||
}, | ||
args: { | ||
text: 'Lorem ipsum dolor', | ||
icon: 'check_circle', | ||
iconAriaLabel: 'Check Circle', | ||
}, | ||
}; | ||
|
||
export const Iconless: Story = { | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?node-id=542%3A8376', | ||
}, | ||
docs: { | ||
description: { | ||
story: 'This is a toast component for displaying a text without an icon.', | ||
}, | ||
}, | ||
}, | ||
args: { | ||
text: 'Lorem ipsum dolor', | ||
}, | ||
}; |
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,30 @@ | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import { render, screen, cleanup } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/vitest'; | ||
|
||
import { Toast } from './Toast'; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
describe('Toast', () => { | ||
it('renders the toast component with text', () => { | ||
const { container } = render(<Toast text="This is a toast message" />); | ||
const toastElement = screen.getByRole('alert'); | ||
expect(toastElement).toBeInTheDocument(); | ||
expect(toastElement).toHaveTextContent('This is a toast message'); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders the toast component with icon', () => { | ||
const { container } = render(<Toast text="This is a toast message" icon="mood" iconAriaLabel="Mood" />); | ||
const toastElement = screen.getByRole('alert'); | ||
const iconElement = screen.getByLabelText('Mood'); | ||
expect(toastElement).toBeInTheDocument(); | ||
expect(toastElement).toHaveTextContent('This is a toast message'); | ||
expect(iconElement).toBeInTheDocument(); | ||
expect(iconElement).toHaveTextContent('mood'); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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,27 @@ | ||
export interface ToastProps { | ||
/** Text shown on the toast */ | ||
text: string; | ||
/** Icon shown on the toast */ | ||
icon?: string; | ||
/** Aria label for the icon */ | ||
iconAriaLabel?: string; | ||
} | ||
|
||
/** | ||
* Toast component for displaying a text. | ||
*/ | ||
export const Toast = ({ text, icon, iconAriaLabel }: ToastProps) => ( | ||
<div | ||
role="alert" | ||
aria-live="assertive" | ||
aria-atomic="true" | ||
className={`inline-flex h-8 items-center gap-3 rounded-[4px] bg-success pl-5 text-body-sm ${icon ? 'pr-7' : 'pr-5'} text-white`} | ||
> | ||
{icon && ( | ||
<span className="material-symbols-outlined size-24 select-none" role="img" aria-label={iconAriaLabel}> | ||
{icon} | ||
</span> | ||
)} | ||
{text} | ||
</div> | ||
); |
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,30 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Toast > renders the toast component with icon 1`] = ` | ||
<div | ||
aria-atomic="true" | ||
aria-live="assertive" | ||
class="inline-flex h-8 items-center gap-3 rounded-[4px] bg-success pl-5 text-body-sm pr-7 text-white" | ||
role="alert" | ||
> | ||
<span | ||
aria-label="Mood" | ||
class="material-symbols-outlined size-24 select-none" | ||
role="img" | ||
> | ||
mood | ||
</span> | ||
This is a toast message | ||
</div> | ||
`; | ||
|
||
exports[`Toast > renders the toast component with text 1`] = ` | ||
<div | ||
aria-atomic="true" | ||
aria-live="assertive" | ||
class="inline-flex h-8 items-center gap-3 rounded-[4px] bg-success pl-5 text-body-sm pr-5 text-white" | ||
role="alert" | ||
> | ||
This is a toast message | ||
</div> | ||
`; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
@import 'symbols.css'; | ||
|
||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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,45 @@ | ||
/* From https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200 */ | ||
|
||
/* fallback */ | ||
@font-face { | ||
font-family: 'Material Symbols Outlined'; | ||
font-style: normal; | ||
font-weight: 100 700; | ||
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v170/kJEhBvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oFsLjBuVY.woff2) | ||
format('woff2'); | ||
} | ||
|
||
.material-symbols-outlined { | ||
-moz-osx-font-smoothing: grayscale; | ||
-webkit-font-smoothing: antialiased; | ||
direction: ltr; | ||
display: inline-block; | ||
font-family: 'Material Symbols Outlined'; | ||
font-feature-settings: 'liga'; | ||
font-size: 24px; | ||
font-style: normal; | ||
font-weight: normal; | ||
letter-spacing: normal; | ||
line-height: 1; | ||
text-transform: none; | ||
white-space: nowrap; | ||
word-wrap: normal; | ||
} | ||
|
||
/* Recommended icon sizes */ | ||
span.size-20 { | ||
font-size: 20px; | ||
font-variation-settings: 'OPSZ' 20; | ||
} | ||
span.size-24 { | ||
font-size: 24px; | ||
font-variation-settings: 'OPSZ' 24; | ||
} | ||
span.size-40 { | ||
font-size: 40px; | ||
font-variation-settings: 'OPSZ' 40; | ||
} | ||
span.size-48 { | ||
font-size: 48px; | ||
font-variation-settings: 'OPSZ' 48; | ||
} |
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