@king-design/intact 3.2.2-beta.0 → 3.3.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.
Files changed (96) hide show
  1. package/components/divider/demos/basic.md +35 -0
  2. package/components/divider/demos/horizontal.md +31 -0
  3. package/components/divider/demos/margin.md +32 -0
  4. package/components/divider/demos/text.md +27 -0
  5. package/components/divider/index.md +16 -0
  6. package/components/divider/index.spec.ts +0 -0
  7. package/components/divider/index.ts +36 -0
  8. package/components/divider/index.vdt +35 -0
  9. package/components/divider/styles.ts +109 -0
  10. package/components/dropdown/dropdown.ts +1 -1
  11. package/components/ellipsis/demos/basic.md +44 -0
  12. package/components/ellipsis/demos/custom.md +36 -0
  13. package/components/ellipsis/demos/position.md +24 -0
  14. package/components/ellipsis/index.md +14 -0
  15. package/components/ellipsis/index.spec.ts +58 -0
  16. package/components/ellipsis/index.ts +36 -0
  17. package/components/ellipsis/index.vdt +39 -0
  18. package/components/ellipsis/styles.ts +22 -0
  19. package/components/ellipsis/useEllipsis.ts +31 -0
  20. package/components/menu/demos/showCollapseArrow.md +7 -4
  21. package/components/menu/item.vdt +6 -3
  22. package/components/menu/styles.ts +8 -8
  23. package/components/menu/title.vdt +2 -1
  24. package/components/table/table.vdt +1 -1
  25. package/components/tag/index.spec.ts +1 -1
  26. package/components/tag/tags.vdt +1 -1
  27. package/components/view/index.ts +24 -0
  28. package/es/components/divider/index.d.ts +14 -0
  29. package/es/components/divider/index.js +38 -0
  30. package/es/components/divider/index.spec.d.ts +1 -0
  31. package/es/components/divider/index.spec.js +1 -0
  32. package/es/components/divider/index.vdt.js +31 -0
  33. package/es/components/divider/styles.d.ts +5 -0
  34. package/es/components/divider/styles.js +35 -0
  35. package/es/components/dropdown/dropdown.js +2 -2
  36. package/es/components/ellipsis/index.d.ts +16 -0
  37. package/es/components/ellipsis/index.js +36 -0
  38. package/es/components/ellipsis/index.spec.d.ts +1 -0
  39. package/es/components/ellipsis/index.spec.js +94 -0
  40. package/es/components/ellipsis/index.vdt.js +50 -0
  41. package/es/components/ellipsis/styles.d.ts +5 -0
  42. package/es/components/ellipsis/styles.js +10 -0
  43. package/es/components/ellipsis/useEllipsis.d.ts +4 -0
  44. package/es/components/ellipsis/useEllipsis.js +21 -0
  45. package/es/components/menu/item.vdt.js +8 -3
  46. package/es/components/menu/styles.d.ts +1 -1
  47. package/es/components/menu/styles.js +6 -5
  48. package/es/components/menu/title.vdt.js +6 -2
  49. package/es/components/table/table.vdt.js +1 -1
  50. package/es/components/tag/index.spec.js +4 -2
  51. package/es/components/tag/tags.vdt.js +2 -1
  52. package/es/components/view/index.d.ts +15 -0
  53. package/es/components/view/index.js +30 -0
  54. package/es/i18n/en-US.d.ts +1 -1
  55. package/es/i18n/en-US.js +1 -1
  56. package/es/index.d.ts +5 -2
  57. package/es/index.js +5 -2
  58. package/es/site/data/components/divider/demos/basic/index.d.ts +9 -0
  59. package/es/site/data/components/divider/demos/basic/index.js +18 -0
  60. package/es/site/data/components/divider/demos/basic/react.d.ts +9 -0
  61. package/es/site/data/components/divider/demos/basic/react.js +27 -0
  62. package/es/site/data/components/divider/demos/horizontal/index.d.ts +6 -0
  63. package/es/site/data/components/divider/demos/horizontal/index.js +14 -0
  64. package/es/site/data/components/divider/demos/horizontal/react.d.ts +5 -0
  65. package/es/site/data/components/divider/demos/horizontal/react.js +26 -0
  66. package/es/site/data/components/divider/demos/margin/index.d.ts +8 -0
  67. package/es/site/data/components/divider/demos/margin/index.js +18 -0
  68. package/es/site/data/components/divider/demos/margin/react.d.ts +7 -0
  69. package/es/site/data/components/divider/demos/margin/react.js +37 -0
  70. package/es/site/data/components/divider/demos/text/index.d.ts +5 -0
  71. package/es/site/data/components/divider/demos/text/index.js +13 -0
  72. package/es/site/data/components/divider/demos/text/react.d.ts +4 -0
  73. package/es/site/data/components/divider/demos/text/react.js +19 -0
  74. package/es/site/data/components/divider/index.d.ts +57 -0
  75. package/es/site/data/components/divider/index.js +32 -0
  76. package/es/site/data/components/ellipsis/demos/basic/index.d.ts +12 -0
  77. package/es/site/data/components/ellipsis/demos/basic/index.js +19 -0
  78. package/es/site/data/components/ellipsis/demos/basic/react.d.ts +12 -0
  79. package/es/site/data/components/ellipsis/demos/basic/react.js +40 -0
  80. package/es/site/data/components/ellipsis/demos/custom/index.d.ts +6 -0
  81. package/es/site/data/components/ellipsis/demos/custom/index.js +14 -0
  82. package/es/site/data/components/ellipsis/demos/custom/react.d.ts +5 -0
  83. package/es/site/data/components/ellipsis/demos/custom/react.js +42 -0
  84. package/es/site/data/components/ellipsis/demos/position/index.d.ts +6 -0
  85. package/es/site/data/components/ellipsis/demos/position/index.js +14 -0
  86. package/es/site/data/components/ellipsis/demos/position/react.d.ts +5 -0
  87. package/es/site/data/components/ellipsis/demos/position/react.js +26 -0
  88. package/es/site/data/components/ellipsis/index.d.ts +57 -0
  89. package/es/site/data/components/ellipsis/index.js +32 -0
  90. package/es/site/data/components/menu/demos/showCollapseArrow/react.js +7 -4
  91. package/es/styles/theme.d.ts +8 -0
  92. package/es/styles/theme.js +8 -4
  93. package/i18n/en-US.ts +1 -1
  94. package/index.ts +5 -2
  95. package/package.json +2 -2
  96. package/styles/theme.ts +4 -0
@@ -0,0 +1,35 @@
1
+ ---
2
+ title: 基本用法
3
+ order: 0
4
+ ---
5
+
6
+ `Divider`组件为区域内容的分割线,`dashed`属性可定义为虚线。
7
+
8
+ ```vdt
9
+ import {Card, Divider} from 'kpc';
10
+
11
+ <div>
12
+ <Card>
13
+ <div>默认直线</div>
14
+ <Divider/>
15
+ <div>虚线</div>
16
+ <Divider borderType={this.get('border')}/>
17
+ </Card>
18
+ </div>
19
+ ```
20
+
21
+ ```ts
22
+
23
+ interface Props {
24
+ border?: 'solid' | 'dashed' | 'dotted' | 'double'
25
+ }
26
+
27
+ export default class extends Component<Props> {
28
+ static template = template;
29
+ static defaults() {
30
+ return {
31
+ border: 'dashed'
32
+ } as Props;
33
+ }
34
+ }
35
+ ```
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: 排列
3
+ order: 2
4
+ ---
5
+
6
+ 通过`type`属性设置排列方式。
7
+
8
+ ```vdt
9
+ import {Card, Divider, Icon} from 'kpc';
10
+
11
+ <div class="divider-content">
12
+ Text
13
+ <Divider type="vertical"></Divider>
14
+ <a href="#">Link</a>
15
+ <Divider type="vertical">Text</Divider>
16
+ <a href="#">Link</a>
17
+ </div>
18
+ ```
19
+
20
+ ```styl
21
+ .divider-content
22
+ height 20px
23
+ display flex
24
+ align-items center
25
+ ```
26
+
27
+ ```ts
28
+ export default class extends Component {
29
+ static template = template;
30
+ }
31
+ ```
@@ -0,0 +1,32 @@
1
+ ---
2
+ title: 外边距
3
+ order: 3
4
+ ---
5
+
6
+ 通过`type`属性设置排列方式。
7
+
8
+ ```vdt
9
+ import {Divider} from 'kpc';
10
+
11
+ <div>
12
+ <div v-for={this.get('margin')}>
13
+ margin {$value}
14
+ <Divider margin={$value}/>
15
+ </div>
16
+ 自定义margin
17
+ <Divider margin={30}/>
18
+ 自定义margin
19
+ <Divider style={{margin: '8px 0 0 0'}}/>
20
+ </div>
21
+ ```
22
+
23
+ ```ts
24
+ export default class extends Component {
25
+ static template = template;
26
+ static defaults() {
27
+ return {
28
+ margin: ['large', 'default', 'small', 'none'] as const
29
+ }
30
+ }
31
+ }
32
+ ```
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: 文字及位置
3
+ order: 1
4
+ ---
5
+
6
+ `Divider`分割线可以设置文字,文字位置通过`position`属性设置。
7
+
8
+ ```vdt
9
+ import {Card, Divider} from 'kpc';
10
+
11
+ <div>
12
+ <Card>
13
+ <div>卡片内容</div>
14
+ <Divider>Text</Divider>
15
+ <div>卡片内容</div>
16
+ <Divider position="left">Text</Divider>
17
+ <div>卡片内容</div>
18
+ <Divider position="right">Text</Divider>
19
+ </Card>
20
+ </div>
21
+ ```
22
+
23
+ ```ts
24
+ export default class extends Component {
25
+ static template = template;
26
+ }
27
+ ```
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: 分割线
3
+ category: 组件
4
+ order: 30
5
+ sidebar: doc
6
+ ---
7
+
8
+ # 属性
9
+
10
+ | 属性 | 说明 | 类型 | 默认值 |
11
+ | --- | --- | --- | --- |
12
+ | borderType | 定义线的类型 | `"solid"` &#124; `"dashed"` &#124; `"dotted"` &#124; `"double"` | `"solid"` |
13
+ | position | 定义文字位置 | `"left"` &#124; `"right"` &#124; `"center"` | `"center"` |
14
+ | type | 定义菜单排列方式:垂直,水平 | `"vertical"` &#124; `"horizontal"` | `"vertical"` |
15
+ | theme | 定义菜单主题 | `"light"` &#124; `"dark"` | `"light"` |
16
+ | margin | 定义`Divider`外边距 | `"large"` &#124; `"default"` &#124; `"small"` &#124; `"none"` &#124; `number` | `"default"` |
File without changes
@@ -0,0 +1,36 @@
1
+ import {Component, TypeDefs} from 'intact';
2
+ import template from './index.vdt';
3
+ import { useConfigContext } from '../config';
4
+
5
+ export interface DividerProps {
6
+ borderType?: 'solid' | 'dashed' | 'dotted' | 'double',
7
+ position?: 'left' | 'right' | 'center',
8
+ type?: 'vertical' | 'horizontal',
9
+ theme?: 'light' | 'dark',
10
+ margin?: 'large' | 'default' | 'small' | 'none' | number,
11
+ }
12
+
13
+ const typeDefs: Required<TypeDefs<DividerProps>> = {
14
+ borderType: ['solid', 'dashed', 'dotted', 'double'],
15
+ position: ['left', 'right', 'center'],
16
+ type: ['vertical', 'horizontal'],
17
+ theme: ['light', 'dark'],
18
+ margin: ['large', 'default', 'small', 'none', Number]
19
+ };
20
+
21
+ const defaults = (): Partial<DividerProps> => ({
22
+ borderType: 'solid',
23
+ position: 'center',
24
+ type: 'horizontal',
25
+ theme: 'light',
26
+ margin: 'default'
27
+ });
28
+
29
+ export class Divider extends Component<DividerProps> {
30
+ static template = template;
31
+ static typeDefs = typeDefs;
32
+ static defaults = defaults;
33
+
34
+ private config = useConfigContext();
35
+ }
36
+
@@ -0,0 +1,35 @@
1
+ import {makeStyles} from './styles';
2
+ import {getRestProps, addStyle} from '../utils';
3
+
4
+ const {
5
+ children, className, borderType,
6
+ position, type, theme, margin,
7
+ style
8
+ } = this.get();
9
+ const { k } = this.config;
10
+ const _style = {};
11
+ if (typeof margin === 'number') {
12
+ const _margin = type === 'vertical' ? `0 ${margin}px` : `${margin}px 0`;
13
+ _style.margin = _margin;
14
+ }
15
+
16
+ const classNameObj = {
17
+ [`${k}-divider`]: true,
18
+ [`${k}-${theme === 'dark' ? 'dark' : 'light'}`]: theme,
19
+ [`${k}-${type}`]: type,
20
+ [`${k}-${margin}`]: margin && typeof margin !== 'number',
21
+ [`${k}-with-text`]: children && type === 'horizontal',
22
+ [`${k}-${position}`]: position !== 'center',
23
+ [makeStyles(k, borderType)]: true,
24
+ [className]: className,
25
+ };
26
+
27
+ <div
28
+ {...getRestProps(this)}
29
+ class={classNameObj}
30
+ style={addStyle(style, _style)}
31
+ >
32
+ <div v-if={children && type === 'horizontal'} class={`${k}-divider-text`}>
33
+ {children}
34
+ </div>
35
+ </div>
@@ -0,0 +1,109 @@
1
+ import {css} from '@emotion/css';
2
+ import {theme, setDefault} from '../../styles/theme';
3
+ import {deepDefaults} from '../../styles/utils';
4
+ import '../../styles/global';
5
+ import { cache } from '../utils';
6
+
7
+ const sizes = ['large', 'default', 'small'] as const;
8
+
9
+ const defaults = {
10
+ positionOffset: '5%',
11
+ get borderColor() { return theme.color.darkBorder },
12
+
13
+ light: {
14
+ get borderColor() { return theme.color.disabledBg },
15
+ },
16
+
17
+ large: {
18
+ get margin() { return theme.large.padding},
19
+ }
20
+
21
+ };
22
+
23
+ let divider: typeof defaults;
24
+ setDefault(() => {
25
+ divider = deepDefaults(theme, {divider: defaults}).divider;
26
+ makeStyles?.clearCache();
27
+ });
28
+
29
+ export const makeStyles = cache(function makeStyles(k: string, borderType: string) {
30
+ return css`
31
+ &.${k}-divider {
32
+ padding: 0;
33
+ border-top: 1px ${borderType} ${divider.borderColor};
34
+ }
35
+
36
+ &.${k}-light {
37
+ border-top-color: ${divider.light.borderColor};
38
+ &.${k}-with-text {
39
+ &::before, &::after {
40
+ border-top-color: ${divider.light.borderColor};
41
+ }
42
+ }
43
+ &.${k}-vertical {
44
+ border-right-color: ${divider.light.borderColor};
45
+ }
46
+ }
47
+
48
+ &.${k}-vertical {
49
+ border-top: 0;
50
+ display: inline-block;
51
+ height: 100%;
52
+ border-right: 1px solid ${divider.borderColor};
53
+ vertical-align: middle;
54
+ }
55
+
56
+ &.${k}-horizontal {
57
+ width: 100%;
58
+ min-width: 100%;
59
+ }
60
+
61
+ &.${k}-with-text {
62
+ border-top: 0;
63
+ display: flex;
64
+ align-items: center;
65
+ white-space: nowrap;
66
+ text-align: center;
67
+ &::before, &::after {
68
+ width: 50%;
69
+ content: '';
70
+ transform: translateY(50%);
71
+ border-top: 1px solid ${divider.borderColor};
72
+ }
73
+ }
74
+
75
+ .${k}-divider-text {
76
+ padding: 0 16px;
77
+ }
78
+
79
+ &.${k}-left {
80
+ &::before {
81
+ width: ${divider.positionOffset};
82
+ }
83
+ &::after {
84
+ width: calc(100% - ${divider.positionOffset});
85
+ }
86
+ }
87
+
88
+ &.${k}-right {
89
+ &::before {
90
+ width: calc(100% - ${divider.positionOffset});
91
+ }
92
+ &::after {
93
+ width: ${divider.positionOffset};
94
+ }
95
+ }
96
+
97
+ // margin sizes
98
+ ${sizes.map(size => {
99
+ return css`
100
+ &.${k}-${size} {
101
+ margin: ${theme[size].margin} 0;
102
+ &.${k}-vertical {
103
+ margin: 0 ${theme[size].margin};
104
+ }
105
+ }
106
+ `;
107
+ })}
108
+ `;
109
+ });
@@ -99,7 +99,7 @@ export class Dropdown<
99
99
  // ignore whitespaces between elements in Vue
100
100
  if ((this as any).$isVue || (this as any).$isVueNext) {
101
101
  if (Array.isArray(children)) {
102
- children = children.filter(child => child !== ' ');
102
+ children = children.filter(child => child !== ' ' && child /* comment is null in vue3 */);
103
103
  }
104
104
  }
105
105
  if (process.env.NODE_ENV !== 'production') {
@@ -0,0 +1,44 @@
1
+ ---
2
+ title: 基本用法
3
+ order: 0
4
+ ---
5
+
6
+ `width`属性可定义可展示的宽度,若不设置`width`,默认父级宽度为准。`maxLines`设置多行忽略最大行数。
7
+
8
+ ```vdt
9
+ import {Ellipsis, Split} from 'kpc';
10
+
11
+ <Split style="width: 400px">
12
+ <b:first>
13
+ <Ellipsis class="panel">测试测试测试测试测试测试</Ellipsis>
14
+ <br/>
15
+ <Ellipsis class="panel" maxLines={2}>最大几行忽略最大几行忽略最大几行忽略</Ellipsis>
16
+ </b:first>
17
+ <b:last>
18
+ <Ellipsis class="panel" disabled={this.get('disabled')}>不展示tooltip不展示tooltip</Ellipsis>
19
+ </b:last>
20
+ </Split>
21
+ ```
22
+
23
+ ```styl
24
+ .k-split
25
+ border 1px solid #ccc
26
+ height 200px
27
+ margin-bottom 20px
28
+ .panel
29
+ margin 10px
30
+ ```
31
+ ```ts
32
+ interface Props {
33
+ disabled?: boolean
34
+ }
35
+ export default class extends Component<Props> {
36
+ static template = template;
37
+
38
+ static defaults() {
39
+ return {
40
+ disabled: true
41
+ };
42
+ }
43
+ }
44
+ ```
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: 自定义内容
3
+ order: 2
4
+ ---
5
+
6
+ `Ellipsis`支持任意自定义内容。
7
+
8
+ ```vdt
9
+ import {Ellipsis, Split, Button, Icon} from 'kpc';
10
+
11
+ <div style={{width: '200px'}}>
12
+ <Ellipsis class="panel tooltip-class">
13
+ <Icon class="ion-heart" />
14
+ <Button type="primary">测试</Button>
15
+ <Icon class="ion-heart" />
16
+ <Button type="primary">测试</Button>
17
+ <Icon class="ion-heart" />
18
+ <Button type="primary">测试</Button>
19
+ <Icon class="ion-heart" />
20
+ <Button type="primary">测试</Button>
21
+ <Icon class="ion-heart" />
22
+ <Button type="primary">测试</Button>
23
+ </Ellipsis>
24
+ </div>
25
+ ```
26
+
27
+ ```styl
28
+ .k-split
29
+ border 1px solid #ccc
30
+ height 200px
31
+ margin-bottom 20px
32
+ .k-btn
33
+ margin 10px
34
+ .panel
35
+ margin 10px
36
+ ```
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: tooltip位置
3
+ order: 1
4
+ ---
5
+
6
+ `position`属性可以设置`tooltip`的位置,参看[Tooltip](https://design.ksyun.com/components/tooltip/?_blank){target="_blank"}组件的`position`属性。
7
+
8
+ ```vdt
9
+ import {Ellipsis} from 'kpc';
10
+
11
+ <div>
12
+ <Ellipsis position="right" style={{width: '90px'}}>tooltip在右侧tooltip在右侧</Ellipsis>
13
+ <Ellipsis position="bottom" style={{width: '90px'}}>tooltip在下方tooltip在下方</Ellipsis>
14
+ </div>
15
+ ```
16
+
17
+ ```styl
18
+ .k-split
19
+ border 1px solid #ccc
20
+ height 200px
21
+ margin-bottom 20px
22
+ .panel
23
+ margin 10px
24
+ ```
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 超长忽略
3
+ category: 组件
4
+ order: 30
5
+ sidebar: doc
6
+ ---
7
+
8
+ # 属性
9
+
10
+ | 属性 | 说明 | 类型 | 默认值 |
11
+ | --- | --- | --- | --- |
12
+ | maxLines | 定义多行省略最大行数 | `number` | `undefined` |
13
+ | position | 菜单弹出的位置,默认在触发器正上方向上偏移`10px`的地方 | `Position` &#124; `"left"` &#124; `"bottom"` &#124; `"right"` &#124; `"top"` | `{my: 'center bottom-10', at: 'center top', collision: 'flipfit'}` |
14
+ | disabled | 定义是否展示tooltip | `boolean` | `false` |
@@ -0,0 +1,58 @@
1
+ import BasicDemo from '~/components/ellipsis/demos/basic';
2
+ import {mount, unmount, dispatchEvent, getElement, wait} from '../../test/utils';
3
+ import {Ellipsis} from './';
4
+
5
+ describe('Ellipsis', () => {
6
+ afterEach(() => unmount());
7
+
8
+ it('should support drag Ellipsis', async () => {
9
+ const [instance, element] = mount(BasicDemo);
10
+ const [ellipsis1, ellipsis2] = element.querySelectorAll<HTMLElement>('.k-ellipsis')!;
11
+
12
+ let dragLine = element.querySelector('.k-split-line-wrapper') as HTMLElement;
13
+ // There is no tooltip content by default
14
+ expect(getElement('.k-tooltip-content')).to.be.undefined;
15
+
16
+ // mouse move
17
+ dispatchEvent(dragLine, 'mousedown', {which: 1, clientX: 200, clientY: 0});
18
+ dispatchEvent(document, 'mousemove', {clientX: 100, clientY: 0});
19
+ dispatchEvent(dragLine, 'mouseup');
20
+ await wait(200);
21
+ expect(element.outerHTML).to.matchSnapshot();
22
+
23
+ // mouseenter ellipsis dom
24
+ const children1 = ellipsis1.firstElementChild!;
25
+ dispatchEvent(children1, 'mouseenter');
26
+ await wait(0);
27
+ expect(children1.classList.contains('k-dropdown-open')).to.be.true;
28
+ let content1 = getElement('.k-tooltip-content')!;
29
+ expect(content1.textContent).eql('测试测试测试测试测试测试');
30
+
31
+ const children2 = ellipsis2.firstElementChild!;
32
+ dispatchEvent(children2, 'mouseenter');
33
+ await wait(0);
34
+ let content2 = getElement('.k-tooltip-content')!;
35
+ expect(content2.textContent).eql('最大几行忽略最大几行忽略最大几行忽略');
36
+ });
37
+
38
+ it('should disabled tooltip', async () => {
39
+ const [instance, element] = mount(BasicDemo);
40
+ const ellipsis3 = element.querySelectorAll<HTMLElement>('.k-ellipsis')[2]!;
41
+ let dragLine = element.querySelector('.k-split-line-wrapper') as HTMLElement;
42
+
43
+ dispatchEvent(dragLine, 'mousedown', {which: 1, clientX: 200, clientY: 0});
44
+ dispatchEvent(document, 'mousemove', {clientX: 300, clientY: 0});
45
+ dispatchEvent(dragLine, 'mouseup');
46
+ await wait(200);
47
+
48
+ // disabled close tooltip
49
+ expect(ellipsis3.firstElementChild!.classList.contains('k-dropdown-open')).to.be.false;
50
+ instance.set('disabled', false);
51
+ await wait();
52
+
53
+ const children3 = ellipsis3.firstElementChild!;
54
+ dispatchEvent(children3, 'mouseenter');
55
+ await wait();
56
+ expect(children3.classList.contains('k-dropdown-open')).to.be.true;
57
+ });
58
+ });
@@ -0,0 +1,36 @@
1
+ import { Component, TypeDefs, createRef } from 'intact';
2
+ import template from './index.vdt';
3
+ import { useEllipsis } from './useEllipsis';
4
+ import { useConfigContext } from '../config';
5
+ import { Options } from '../position';
6
+
7
+ export type Position = Options;
8
+ export interface EllipsisProps {
9
+ maxLines?: number,
10
+ disabled?: boolean,
11
+ position?: Position | 'left' | 'bottom' | 'right' | 'top',
12
+ theme?: 'light' | 'dark',
13
+ }
14
+
15
+ const typeDefs: Required<TypeDefs<EllipsisProps>> = {
16
+ maxLines: Number,
17
+ disabled: Boolean,
18
+ position: [Object, 'left', 'bottom', 'right', 'top'],
19
+ theme: ['light', 'dark'],
20
+ };
21
+
22
+ const defaults = (): Partial<EllipsisProps> => ({
23
+ disabled: false,
24
+ theme: 'light'
25
+ });
26
+
27
+ export class Ellipsis extends Component<EllipsisProps> {
28
+ static template = template;
29
+ static typeDefs = typeDefs;
30
+ static defaults = defaults;
31
+
32
+ private ellipsis = useEllipsis();
33
+
34
+ private config = useConfigContext();
35
+ }
36
+
@@ -0,0 +1,39 @@
1
+ import { makeStyles } from './styles';
2
+ import {Tooltip} from '../tooltip';
3
+ import {getRestProps, addStyle} from '../utils';
4
+
5
+ const {
6
+ children, className, maxLines,
7
+ disabled, position, theme, style
8
+ } = this.get();
9
+ const { k } = this.config;
10
+
11
+ const { showTooltip, ellipsisRef } = this.ellipsis;
12
+ const tooltip = showTooltip.value && !disabled;
13
+ const wrapper = <div class={{
14
+ 'c-ellipsis': true,
15
+ [`${k}-ellipsis-wrapper`]: true,
16
+ [className]: className && !tooltip,
17
+ }}>{children}</div>;
18
+
19
+ <div
20
+ {...getRestProps(this)}
21
+ class={{
22
+ [`${k}-ellipsis`]: true,
23
+ [`${k}-multiline`]: maxLines,
24
+ [makeStyles(k, maxLines)]: true,
25
+ }}
26
+ ref={ellipsisRef}
27
+ >
28
+ <Tooltip
29
+ v-if={tooltip}
30
+ position={position}
31
+ theme={theme}
32
+ class={className}
33
+ >
34
+ {wrapper}
35
+ <b:content>{children}</b:content>
36
+ </Tooltip>
37
+ <template v-else>{wrapper}</template>
38
+ </div>
39
+
@@ -0,0 +1,22 @@
1
+ import {css} from '@emotion/css';
2
+ import {setDefault} from '../../styles/theme';
3
+ import '../../styles/global';
4
+ import { cache } from '../utils';
5
+
6
+ setDefault(() => {
7
+ makeStyles?.clearCache();
8
+ });
9
+
10
+ export const makeStyles = cache(function makeStyles(k: string, maxLines: number) {
11
+ return css`
12
+ width: 100%;
13
+ &.${k}-multiline {
14
+ .k-ellipsis-wrapper {
15
+ white-space: normal;
16
+ display: -webkit-box;
17
+ -webkit-line-clamp: ${maxLines};
18
+ -webkit-box-orient: vertical;
19
+ }
20
+ }
21
+ `;
22
+ });
@@ -0,0 +1,31 @@
1
+ import {useInstance, createRef} from 'intact';
2
+ import type {Ellipsis} from './';
3
+ import { useResizeObserver } from '../../hooks/useResizeObserver';
4
+ import { useState } from '../../hooks/useState';
5
+
6
+ export function useEllipsis() {
7
+ const instance = useInstance() as Ellipsis;
8
+ const ellipsisRef = createRef<HTMLDivElement>();
9
+ let showTooltip = useState<boolean>(false);
10
+
11
+ useResizeObserver(ellipsisRef, isShowTooltip);
12
+
13
+ function isShowTooltip() {
14
+ const isMulti = instance.get('maxLines');
15
+ const element = ellipsisRef.value!.children[0] as HTMLDivElement;
16
+
17
+ const _showTooltip = isMulti
18
+ ? element.scrollHeight > element.clientHeight
19
+ : element.offsetWidth < element.scrollWidth;
20
+
21
+ requestAnimationFrame(() => {
22
+ showTooltip.set(_showTooltip);
23
+ });
24
+ }
25
+
26
+
27
+ return {
28
+ ellipsisRef,
29
+ showTooltip
30
+ };
31
+ }