This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRNT-499 create toast component (#121)
* fix button padding * create toast component * fix lint styles * resolve comments * fix toast styles and description * fix toast styles and description * fix usage * update lint * update lint * update lint
- Loading branch information
1 parent
78f13fc
commit eca2a1f
Showing
4 changed files
with
271 additions
and
6 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
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,98 @@ | ||
import * as React from 'react'; | ||
import styled, { StyledComponent } from 'styled-components'; | ||
import { Variant } from 'lib/types'; | ||
import { box } from 'ui/elements'; | ||
|
||
interface ToastProps { | ||
action?: React.ReactNode; | ||
className?: string; | ||
icon?: React.ReactNode; | ||
outlined?: boolean; | ||
} | ||
|
||
const ToastBase: React.FC<ToastProps & Variant> = ({ | ||
action, | ||
children, | ||
className, | ||
icon, | ||
outlined = false, | ||
variant = 'secondary', | ||
}) => ( | ||
<div className={className} data-outlined={outlined} data-variant={variant}> | ||
{icon && <span data-icon="toast">{icon}</span>} | ||
<div data-content>{children}</div> | ||
{action && <span data-action>{action}</span>} | ||
</div> | ||
); | ||
|
||
export const Toast = styled(ToastBase)` | ||
${box} | ||
--local-text-color: var(--woly-shape-text-default); | ||
--local-shape-color: var(--woly-shape-default); | ||
--local-border-color: var(--woly-shape-default); | ||
--local-toast-gap: max(9px, calc(1px * var(--woly-component-level) * var(--woly-main-level))); | ||
display: flex; | ||
flex-wrap: nowrap; | ||
align-items: center; | ||
min-width: fit-content; | ||
max-width: 75%; | ||
color: var(--local-text-color); | ||
font-size: var(--woly-font-size); | ||
line-height: var(--woly-line-height); | ||
background-color: var(--local-shape-color); | ||
border: var(--woly-border-width) solid var(--local-border-color); | ||
border-radius: var(--woly-rounding); | ||
outline: none; | ||
&[data-outlined='true'] { | ||
color: var(--local-shape-color); | ||
background-color: transparent; | ||
[data-icon='toast'] { | ||
svg > path { | ||
fill: var(--local-shape-color); | ||
} | ||
} | ||
} | ||
[data-content] { | ||
display: flex; | ||
flex: 1; | ||
flex-wrap: nowrap; | ||
} | ||
[data-icon='toast'] { | ||
--woly-component-level: 0; | ||
--local-icon-size: var(--woly-line-height); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: var(--local-icon-size); | ||
height: var(--local-icon-size); | ||
} | ||
[data-action] { | ||
--woly-component-level: 0; | ||
display: flex; | ||
align-items: center; | ||
& > *:not(:last-child) { | ||
margin-right: var(--local-toast-gap); | ||
} | ||
} | ||
&:hover { | ||
--local-text-color: var(--woly-shape-text-hover); | ||
--local-border-color: var(--woly-shape-hover); | ||
--local-shape-color: var(--woly-shape-hover); | ||
} | ||
&:focus { | ||
box-shadow: 0 0 0 var(--woly-border-width) var(--woly-focus); | ||
} | ||
` as StyledComponent<'div', Record<string, unknown>, ToastProps & Variant>; |
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,164 @@ | ||
--- | ||
name: toast | ||
category: molecules | ||
package: 'woly' | ||
--- | ||
|
||
import { Button, Toast } from 'ui'; | ||
import { IconPlus, IconSearch } from 'static/icons'; | ||
import { block, Playground, State } from 'lib/playground'; | ||
|
||
`Toast` is lightweight notification designed to mimic the push notifications. | ||
Toast is intended to be small interruptions to your visitors or users, | ||
and therefore should contain minimal, to-the-point, non-interactive content. | ||
|
||
### Example | ||
|
||
Siple Toast with text only | ||
|
||
<Playground> | ||
<block.L> | ||
<Toast variant="primary" outlined> | ||
Режим предпросмотра таблицы | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
### Icons | ||
|
||
Toast can be used with icon on the left side. | ||
|
||
<Playground> | ||
<block.L> | ||
<Toast icon={<IconPlus />} variant="primary" outlined> | ||
Перетащите файл формата XLS | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
Toast can also consist action block | ||
|
||
<Playground> | ||
<block.L style={{ width: '1200px' }}> | ||
<Toast | ||
variant="primary" | ||
outlined | ||
action={ | ||
<> | ||
<Button | ||
icon={<IconSearch />} | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="primary" | ||
text="Submit" | ||
/> | ||
<Button | ||
icon={<IconSearch />} | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="secondary" | ||
text="Cancel" | ||
outlined | ||
/> | ||
</> | ||
} | ||
> | ||
Перетащите файл формата XLS, чтобы обновить данные о тарифах | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
Or even both | ||
|
||
<Playground> | ||
<block.L style={{ width: '1200px' }}> | ||
<Toast | ||
icon={<IconPlus />} | ||
variant="primary" | ||
outlined | ||
action={ | ||
<> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="primary" | ||
text="Submit" | ||
/> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="primary" | ||
text="Cancel" | ||
outlined | ||
/> | ||
</> | ||
} | ||
> | ||
Сохраните изменения, чтобы выйти из режима предпросмотра | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
### Variants | ||
|
||
<Playground> | ||
<block.L style={{ width: '1200px' }}> | ||
<Toast | ||
icon={<IconPlus />} | ||
variant="secondary" | ||
outlined | ||
action={ | ||
<> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="secondary" | ||
text="Submit" | ||
outlined | ||
/> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="secondary" | ||
text="Cancel" | ||
outlined | ||
/> | ||
</> | ||
} | ||
> | ||
Сохраните изменения, чтобы выйти из режима предпросмотра | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
<Playground> | ||
<block.L style={{ width: '1200px' }}> | ||
<Toast | ||
icon={<IconPlus />} | ||
variant="primary" | ||
outlined | ||
action={ | ||
<> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="primary" | ||
text="Submit" | ||
outlined | ||
/> | ||
<Button | ||
onClick={() => console.info('IconClose clicked')} | ||
variant="primary" | ||
text="Cancel" | ||
outlined | ||
/> | ||
</> | ||
} | ||
> | ||
Сохраните изменения, чтобы выйти из режима предпросмотра | ||
</Toast> | ||
</block.L> | ||
</Playground> | ||
|
||
### Props | ||
|
||
| Name | Type | Default | Description | | ||
| ---------- | ------------------ | ------------- | --------------------------------------------------------------------- | | ||
| `action` | `React.ReactNode` | `null` | Block of action items (ex. One element or grop that can be clicked) | | ||
| `content` | `React.ReactNode` | `null` | Component to show the icon near the text (ex.: Icon on the left side) | | ||
| `children` | ``React.ReactNode` | `null` | Content block | | ||
| `outlined` | `boolean` | `false` | Change toast`s view from filled to outlined | | ||
| `variant` | `string` | `'secondary'` | Variant prop to style Toast component | |