@charcoal-ui/react 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/TextEllipsis/helper.d.ts +4 -0
- package/dist/components/TextEllipsis/helper.d.ts.map +1 -0
- package/dist/components/TextEllipsis/index.d.ts +10 -0
- package/dist/components/TextEllipsis/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +21 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layered.css +21 -0
- package/dist/layered.css.map +1 -1
- package/package.json +5 -5
- package/src/components/TextEllipsis/TextEllipsis.story.tsx +63 -0
- package/src/components/TextEllipsis/helper.ts +50 -0
- package/src/components/TextEllipsis/index.css +20 -0
- package/src/components/TextEllipsis/index.tsx +43 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.charcoal-text-ellipsis {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
line-height: var(--charcoal-text-ellipsis-line-height);
|
|
4
|
+
overflow-wrap: break-word;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.charcoal-text-ellipsis[data-line-limit='1'] {
|
|
8
|
+
text-overflow: ellipsis;
|
|
9
|
+
white-space: nowrap;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.charcoal-text-ellipsis[data-line-limit]:not([data-line-limit='1']) {
|
|
13
|
+
display: -webkit-box;
|
|
14
|
+
-webkit-box-orient: vertical;
|
|
15
|
+
-webkit-line-clamp: var(--charcoal-text-ellipsis-line-limit);
|
|
16
|
+
max-height: calc(
|
|
17
|
+
var(--charcoal-text-ellipsis-line-height) *
|
|
18
|
+
var(--charcoal-text-ellipsis-line-limit)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import './index.css'
|
|
2
|
+
|
|
3
|
+
import { onlyText } from './helper'
|
|
4
|
+
import { useClassNames } from '../../_lib/useClassNames'
|
|
5
|
+
|
|
6
|
+
export type TextEllipsisProps = {
|
|
7
|
+
lineHeight: number
|
|
8
|
+
lineLimit?: number
|
|
9
|
+
} & React.ComponentPropsWithoutRef<'div'>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 複数行のテキストに表示行数制限を設けて`...`で省略する
|
|
13
|
+
*/
|
|
14
|
+
export default function TextEllipsis({
|
|
15
|
+
lineHeight,
|
|
16
|
+
lineLimit = 1,
|
|
17
|
+
children,
|
|
18
|
+
title,
|
|
19
|
+
...props
|
|
20
|
+
}: TextEllipsisProps) {
|
|
21
|
+
const resolvedTitle = title === undefined ? onlyText(children) : title
|
|
22
|
+
const finalTitle = resolvedTitle !== '' ? resolvedTitle : undefined
|
|
23
|
+
|
|
24
|
+
const classNames = useClassNames('charcoal-text-ellipsis', props.className)
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
{...props}
|
|
29
|
+
className={classNames}
|
|
30
|
+
data-line-limit={lineLimit}
|
|
31
|
+
style={
|
|
32
|
+
{
|
|
33
|
+
'--charcoal-text-ellipsis-line-height': `${lineHeight}px`,
|
|
34
|
+
'--charcoal-text-ellipsis-line-limit': lineLimit,
|
|
35
|
+
...props.style,
|
|
36
|
+
} satisfies React.CSSProperties
|
|
37
|
+
}
|
|
38
|
+
title={finalTitle}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|