@charcoal-ui/react 5.4.0 → 5.4.1

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.
Files changed (37) hide show
  1. package/dist/components/TextEllipsis/helper.d.ts +1 -0
  2. package/dist/components/TextEllipsis/helper.d.ts.map +1 -1
  3. package/dist/components/TextEllipsis/index.d.ts +6 -2
  4. package/dist/components/TextEllipsis/index.d.ts.map +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.css +8 -5
  8. package/dist/index.css.map +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/layered.css +8 -5
  12. package/dist/layered.css.map +1 -1
  13. package/package.json +5 -5
  14. package/src/components/Button/index.story.tsx +1 -1
  15. package/src/components/Checkbox/CheckboxInput/index.story.tsx +1 -1
  16. package/src/components/Checkbox/index.story.tsx +1 -1
  17. package/src/components/Clickable/index.story.tsx +1 -1
  18. package/src/components/DropdownSelector/ListItem/index.story.tsx +1 -1
  19. package/src/components/DropdownSelector/MenuList/index.story.tsx +1 -1
  20. package/src/components/DropdownSelector/Popover/index.story.tsx +1 -1
  21. package/src/components/DropdownSelector/index.story.tsx +1 -1
  22. package/src/components/HintText/index.story.tsx +1 -1
  23. package/src/components/Icon/index.story.tsx +1 -1
  24. package/src/components/IconButton/index.story.tsx +1 -1
  25. package/src/components/LoadingSpinner/index.story.tsx +1 -1
  26. package/src/components/Modal/index.story.tsx +1 -1
  27. package/src/components/MultiSelect/index.story.tsx +1 -1
  28. package/src/components/Radio/index.story.tsx +1 -1
  29. package/src/components/SegmentedControl/index.story.tsx +1 -1
  30. package/src/components/Switch/index.story.tsx +1 -1
  31. package/src/components/TagItem/index.story.tsx +1 -1
  32. package/src/components/TextArea/TextArea.story.tsx +1 -1
  33. package/src/components/TextEllipsis/TextEllipsis.story.tsx +58 -0
  34. package/src/components/TextEllipsis/helper.ts +22 -0
  35. package/src/components/TextEllipsis/index.css +8 -5
  36. package/src/components/TextEllipsis/index.tsx +15 -5
  37. package/src/components/TextField/TextField.story.tsx +1 -1
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from '@storybook/react-webpack5'
1
+ import { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import LoadingSpinner from '.'
3
3
 
4
4
  export default {
@@ -12,7 +12,7 @@ import TextField from '../TextField'
12
12
  import DropdownSelector from '../DropdownSelector'
13
13
  import Checkbox from '../Checkbox'
14
14
  import DropdownMenuItem from '../DropdownSelector/DropdownMenuItem'
15
- import { Meta, StoryObj } from '@storybook/react-webpack5'
15
+ import { Meta, StoryObj } from '@storybook/react-vite'
16
16
 
17
17
  export default {
18
18
  title: 'react/Modal',
@@ -4,7 +4,7 @@ import {
4
4
  default as MultiSelect,
5
5
  MultiSelectGroupProps,
6
6
  } from '.'
7
- import { Meta, StoryObj } from '@storybook/react-webpack5'
7
+ import { Meta, StoryObj } from '@storybook/react-vite'
8
8
  import { action } from 'storybook/actions'
9
9
 
10
10
  const StyledMultiSelectGroup = (props: MultiSelectGroupProps) => {
@@ -1,6 +1,6 @@
1
1
  import Radio from '.'
2
2
  import { RadioGroup } from './RadioGroup'
3
- import { StoryObj } from '@storybook/react-webpack5'
3
+ import { StoryObj } from '@storybook/react-vite'
4
4
  import { useState } from 'react'
5
5
 
6
6
  export default {
@@ -1,5 +1,5 @@
1
1
  import SegmentedControl from '.'
2
- import { Meta, StoryObj } from '@storybook/react-webpack5'
2
+ import { Meta, StoryObj } from '@storybook/react-vite'
3
3
 
4
4
  export default {
5
5
  title: 'react/SegmentedControl',
@@ -1,6 +1,6 @@
1
1
  import { useState } from 'react'
2
2
  import Switch from '.'
3
- import { Meta, StoryObj } from '@storybook/react-webpack5'
3
+ import { Meta, StoryObj } from '@storybook/react-vite'
4
4
 
5
5
  export default {
6
6
  title: 'react/Switch',
@@ -1,5 +1,5 @@
1
1
  import TagItem from '.'
2
- import { Meta, StoryObj } from '@storybook/react-webpack5'
2
+ import { Meta, StoryObj } from '@storybook/react-vite'
3
3
 
4
4
  export default {
5
5
  title: 'react/TagItem',
@@ -1,7 +1,7 @@
1
1
  import { action } from 'storybook/actions'
2
2
  import Clickable from '../Clickable'
3
3
  import TextArea from '.'
4
- import { Meta, StoryObj } from '@storybook/react-webpack5'
4
+ import { Meta, StoryObj } from '@storybook/react-vite'
5
5
 
6
6
  export default {
7
7
  title: 'react/TextArea',
@@ -61,3 +61,61 @@ export const EmptyTitle: StoryObj<typeof TextEllipsis> = {
61
61
  'title="" を渡すとツールチップは表示されません。ホバーしても何も出ません。',
62
62
  },
63
63
  }
64
+
65
+ const narrowRender = (args: React.ComponentProps<typeof TextEllipsis>) => (
66
+ <div style={{ width: 80 }} lang="en">
67
+ <TextEllipsis {...args} />
68
+ </div>
69
+ )
70
+
71
+ export const HyphensAuto: StoryObj<typeof TextEllipsis> = {
72
+ args: {
73
+ lineHeight: 24,
74
+ lineLimit: 2,
75
+ hyphens: 'auto',
76
+ children: 'internationalization',
77
+ },
78
+ render: narrowRender,
79
+ }
80
+
81
+ export const HyphensManual: StoryObj<typeof TextEllipsis> = {
82
+ args: {
83
+ lineHeight: 24,
84
+ lineLimit: 2,
85
+ hyphens: 'manual',
86
+ children: 'inter\u00ADnational\u00ADization',
87
+ },
88
+ render: narrowRender,
89
+ }
90
+
91
+ export const HyphensNone: StoryObj<typeof TextEllipsis> = {
92
+ args: {
93
+ lineHeight: 24,
94
+ lineLimit: 2,
95
+ hyphens: 'none',
96
+ children: 'internationalization',
97
+ },
98
+ render: narrowRender,
99
+ }
100
+
101
+ export const LineHeightInherit: StoryObj<typeof TextEllipsis> = {
102
+ args: {
103
+ lineLimit: 2,
104
+ children: 'lineHeight を指定しない場合、親の line-height を継承します。',
105
+ },
106
+ render: (args) => (
107
+ <div style={{ lineHeight: 1.8, width: 200 }}>
108
+ <TextEllipsis {...args} />
109
+ </div>
110
+ ),
111
+ }
112
+
113
+ export const ShowTooltipFalse: StoryObj<typeof TextEllipsis> = {
114
+ args: {
115
+ lineHeight: 24,
116
+ lineLimit: 1,
117
+ showTooltip: false,
118
+ children:
119
+ 'showTooltip=false の場合、ホバーしてもツールチップは表示されません。',
120
+ },
121
+ }
@@ -2,6 +2,28 @@
2
2
 
3
3
  import { Children, isValidElement, ReactElement, ReactNode } from 'react'
4
4
 
5
+ export const getFinalTitle = (
6
+ showTooltip: boolean,
7
+ title?: string,
8
+ children?: ReactNode,
9
+ ): string | undefined => {
10
+ // 1. 表示フラグが false なら即終了
11
+ if (!showTooltip) {
12
+ return undefined
13
+ }
14
+
15
+ // 2. タイトルの候補を取得
16
+ const resolvedTitle = title ?? onlyText(children)
17
+
18
+ // 3. resolvedTitle が falsy (undefined, null, "") なら終了
19
+ if (!resolvedTitle) {
20
+ return undefined
21
+ }
22
+
23
+ // 4. 有効な文字列のみを返す
24
+ return resolvedTitle
25
+ }
26
+
5
27
  const hasChildren = (
6
28
  element: ReactNode,
7
29
  ): element is ReactElement<{ children: ReactNode[] }> =>
@@ -1,9 +1,16 @@
1
1
  .charcoal-text-ellipsis {
2
2
  overflow: hidden;
3
- line-height: var(--charcoal-text-ellipsis-line-height);
4
3
  overflow-wrap: break-word;
5
4
  }
6
5
 
6
+ .charcoal-text-ellipsis[data-has-line-height='true'] {
7
+ line-height: var(--charcoal-text-ellipsis-line-height);
8
+ }
9
+
10
+ .charcoal-text-ellipsis[data-has-line-height='false'] {
11
+ line-height: inherit;
12
+ }
13
+
7
14
  .charcoal-text-ellipsis[data-line-limit='1'] {
8
15
  text-overflow: ellipsis;
9
16
  white-space: nowrap;
@@ -13,8 +20,4 @@
13
20
  display: -webkit-box;
14
21
  -webkit-box-orient: vertical;
15
22
  -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
23
  }
@@ -1,11 +1,15 @@
1
1
  import './index.css'
2
2
 
3
- import { onlyText } from './helper'
3
+ import { getFinalTitle } from './helper'
4
4
  import { useClassNames } from '../../_lib/useClassNames'
5
+ import { CSSProperties } from 'react'
5
6
 
6
7
  export type TextEllipsisProps = {
7
- lineHeight: number
8
+ lineHeight?: number
8
9
  lineLimit?: number
10
+ hyphens?: CSSProperties['hyphens']
11
+ /** html title属性を付与。false のときは付与せず、空文字のときは表示しない */
12
+ showTooltip?: boolean
9
13
  } & React.ComponentPropsWithoutRef<'div'>
10
14
 
11
15
  /**
@@ -16,22 +20,28 @@ export default function TextEllipsis({
16
20
  lineLimit = 1,
17
21
  children,
18
22
  title,
23
+ hyphens = 'auto',
24
+ showTooltip = true,
19
25
  ...props
20
26
  }: TextEllipsisProps) {
21
- const resolvedTitle = title === undefined ? onlyText(children) : title
22
- const finalTitle = resolvedTitle !== '' ? resolvedTitle : undefined
27
+ const finalTitle = getFinalTitle(showTooltip, title, children)
23
28
 
24
29
  const classNames = useClassNames('charcoal-text-ellipsis', props.className)
30
+ const hasLineHeight = lineHeight !== undefined
25
31
 
26
32
  return (
27
33
  <div
28
34
  {...props}
29
35
  className={classNames}
30
36
  data-line-limit={lineLimit}
37
+ data-has-line-height={hasLineHeight}
31
38
  style={
32
39
  {
33
- '--charcoal-text-ellipsis-line-height': `${lineHeight}px`,
40
+ ...(hasLineHeight && {
41
+ '--charcoal-text-ellipsis-line-height': `${lineHeight}px`,
42
+ }),
34
43
  '--charcoal-text-ellipsis-line-limit': lineLimit,
44
+ hyphens,
35
45
  ...props.style,
36
46
  } satisfies React.CSSProperties
37
47
  }
@@ -1,7 +1,7 @@
1
1
  import Clickable from '../Clickable'
2
2
  import TextField from '.'
3
3
  import { useState } from 'react'
4
- import { Meta, StoryObj } from '@storybook/react-webpack5'
4
+ import { Meta, StoryObj } from '@storybook/react-vite'
5
5
 
6
6
  export default {
7
7
  title: 'react/TextField',