Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit deac97f

Browse files
authored
feat(toast): support two lines label in Toast (#49)
Closes #16
1 parent bfc02e9 commit deac97f

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

packages/core/src/Dialog/Dialog.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@ import { Header } from './components/Header'
2222
import { Footer } from './components/Footer'
2323
import { MainSection } from './components/Content'
2424
import { BaseDialog, DialogWidth } from './BaseDialog'
25+
import { twoLinesClamp } from '../utils/twoLinesClamp'
2526

2627
export const HeaderTitle = styled(Typography).attrs({
2728
variant: 'dialog-heading',
2829
})`
29-
/* stylelint-disable-next-line value-no-vendor-prefix */
30-
display: -webkit-box;
31-
/* stylelint-disable-next-line property-no-vendor-prefix */
32-
-webkit-line-clamp: 2;
33-
/* stylelint-disable-next-line property-no-vendor-prefix */
34-
-webkit-box-orient: vertical;
35-
/* stylelint-disable-next-line property-no-vendor-prefix */
36-
-moz-box-orient: vertical;
37-
overflow: hidden;
30+
${twoLinesClamp}
3831
`
3932

4033
export interface DialogProps extends ModalProps {

packages/core/src/Toast/toastCreators.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
BaseToastValue,
2222
} from './context'
2323
import { Theme } from '../theme'
24+
import { twoLinesClamp } from '../utils/twoLinesClamp'
2425

2526
const getIconColor = (theme: Theme, iconType?: ToastIconType) => {
2627
const { color } = theme
@@ -48,6 +49,7 @@ export const ToastLabel = styled(Typography).attrs({
4849
readonly hasEmphasis: boolean
4950
}>`
5051
height: 100%;
52+
${twoLinesClamp}
5153
5254
${({ hasCloseButton }) =>
5355
!hasCloseButton

packages/core/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './withField'
2+
export * from './twoLinesClamp'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { css } from 'styled-components'
2+
3+
/**
4+
* A styled-components mixin that truncates two-lines text with ellipsis.
5+
*
6+
* An example:
7+
* ```tsx
8+
* const Div = styled.div`
9+
* ${twoLinesClamp};
10+
* `
11+
* ```
12+
*/
13+
export const twoLinesClamp = css`
14+
/* stylelint-disable-next-line value-no-vendor-prefix */
15+
display: -webkit-box;
16+
/* stylelint-disable-next-line property-no-vendor-prefix */
17+
-webkit-line-clamp: 2;
18+
/* stylelint-disable-next-line property-no-vendor-prefix */
19+
-webkit-box-orient: vertical;
20+
/* stylelint-disable-next-line property-no-vendor-prefix */
21+
-moz-box-orient: vertical;
22+
overflow: hidden;
23+
white-space: pre-wrap;
24+
`

0 commit comments

Comments
 (0)