@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.
@@ -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
+ }
package/src/index.ts CHANGED
@@ -79,3 +79,7 @@ export {
79
79
  type HintTextProps,
80
80
  type HintTextContext,
81
81
  } from './components/HintText'
82
+ export {
83
+ default as UnstableTextEllipsis,
84
+ type TextEllipsisProps,
85
+ } from './components/TextEllipsis'