@onereach/ui-components 2.74.2 → 2.74.3-beta.2300.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 (28) hide show
  1. package/dist/bundled/v2/{OrText-a665b991.js → OrText-15bf85c4.js} +36 -3
  2. package/dist/bundled/v2/components/index.js +1 -1
  3. package/dist/bundled/v2/components/or-text-v3/OrText.stories3.d.ts +13 -1
  4. package/dist/bundled/v2/components/or-text-v3/OrText.vue.d.ts +27 -2
  5. package/dist/bundled/v2/components/or-text-v3/index.js +1 -1
  6. package/dist/bundled/v2/index.js +2 -2
  7. package/dist/bundled/v3/OrText.vue_vue_type_script_lang-e93438ea.js +93 -0
  8. package/dist/bundled/v3/components/index.js +1 -1
  9. package/dist/bundled/v3/components/or-text-v3/OrText.stories3.d.ts +13 -1
  10. package/dist/bundled/v3/components/or-text-v3/OrText.vue.d.ts +27 -2
  11. package/dist/bundled/v3/components/or-text-v3/index.js +1 -1
  12. package/dist/bundled/v3/index.js +3 -3
  13. package/dist/esm/v2/{OrText-b12d0682.js → OrText-91d662a0.js} +36 -3
  14. package/dist/esm/v2/components/index.js +1 -1
  15. package/dist/esm/v2/components/or-text-v3/OrText.stories3.d.ts +13 -1
  16. package/dist/esm/v2/components/or-text-v3/OrText.vue.d.ts +27 -2
  17. package/dist/esm/v2/components/or-text-v3/index.js +1 -1
  18. package/dist/esm/v2/index.js +1 -1
  19. package/dist/esm/v3/{OrText-6b4f7cd1.js → OrText-a3b00048.js} +36 -3
  20. package/dist/esm/v3/components/index.js +1 -1
  21. package/dist/esm/v3/components/or-text-v3/OrText.stories3.d.ts +13 -1
  22. package/dist/esm/v3/components/or-text-v3/OrText.vue.d.ts +27 -2
  23. package/dist/esm/v3/components/or-text-v3/index.js +1 -1
  24. package/dist/esm/v3/index.js +1 -1
  25. package/package.json +2 -3
  26. package/src/components/or-text-v3/OrText.stories3.ts +81 -5
  27. package/src/components/or-text-v3/OrText.vue +37 -3
  28. package/dist/bundled/v3/OrText.vue_vue_type_script_lang-271fb345.js +0 -60
@@ -17,16 +17,31 @@ const RestText = [
17
17
  // Layout
18
18
  'shrink'];
19
19
 
20
+ /**
21
+ * Use `OrText` component to crop un-wrapped single-line text with ellipsis inside narrow containers.
22
+ * Ellipsis can be placed in the end or in the middle of the text. Convenient for displaying long labels,
23
+ * that have same beginning and differ in the ending part.
24
+ */
20
25
  var script = defineComponent({
21
26
  name: 'OrText',
22
27
  props: {
28
+ /**
29
+ * Text to crop.
30
+ */
23
31
  text: {
24
32
  type: String,
25
33
  required: true
26
34
  },
35
+ /**
36
+ * The index counted from the end of the string where ellipsis will be placed.
37
+ * Defines how many ending characters will remain visible.
38
+ * By default, ellipsis is placed in the end of the line.
39
+ *
40
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
41
+ */
27
42
  sliceIndex: {
28
43
  type: Number,
29
- default: undefined
44
+ default: 0
30
45
  }
31
46
  },
32
47
  expose: ['root'],
@@ -37,15 +52,33 @@ var script = defineComponent({
37
52
  const rootStyles = computed(() => ['or-text', ...TextRoot]);
38
53
  const mainTextStyles = computed(() => [...MainText]);
39
54
  const restTextStyles = computed(() => [...RestText]);
55
+ /**
56
+ * Preserves whitespace at the last position as <code>&nbsp;</code>
57
+ * @param str A string to escape
58
+ */
59
+ const escapeLast = str => str && str.slice(0, -1) + '\xa0';
60
+ /**
61
+ * Preserves whitespace at the first position as <code>&nbsp;</code>
62
+ * @param str A string to escape
63
+ */
64
+ const escapeFirst = str => str && '\xa0' + str.slice(1);
40
65
  // State
41
66
  const mainText = computed(() => {
42
67
  if (props.sliceIndex) {
43
- return props.text.slice(0, Math.abs(props.sliceIndex) * -1);
68
+ let mainPart = props.text.slice(0, -Math.abs(props.sliceIndex));
69
+ if (mainPart[mainPart.length - 1] === ' ') {
70
+ mainPart = escapeLast(mainPart);
71
+ }
72
+ return mainPart;
44
73
  }
45
74
  return props.text;
46
75
  });
47
76
  const restText = computed(() => {
48
- return props.text.slice(mainText.value.length);
77
+ let restPart = props.text.slice(mainText.value.length);
78
+ if (restPart[0] === ' ') {
79
+ restPart = escapeFirst(restPart);
80
+ }
81
+ return restPart;
49
82
  });
50
83
  return {
51
84
  root,
@@ -89,7 +89,7 @@ export { _ as OrTag } from '../OrTag-c1fa6901.js';
89
89
  export { _ as OrTagV3, a as TagColor, T as TagVariant } from '../OrTag-920c6371.js';
90
90
  export { _ as OrTeleport } from '../OrTeleportVue2-8ef4ceca.js';
91
91
  export { _ as OrTeleportV3 } from '../OrTeleport.vue2-fb92f29f.js';
92
- export { _ as OrTextV3 } from '../OrText-b12d0682.js';
92
+ export { _ as OrTextV3 } from '../OrText-91d662a0.js';
93
93
  export { _ as OrTextarea } from '../OrTextarea-91a95068.js';
94
94
  export { _ as OrTextareaV3 } from '../OrTextarea-373d0554.js';
95
95
  export { _ as OrTextbox, T as TextboxTypes } from '../OrTextbox-2594c980.js';
@@ -1,12 +1,24 @@
1
1
  import { Meta, StoryFn } from '@storybook/vue3';
2
+ import OrText from './OrText.vue';
2
3
  declare const _default: Meta<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
3
4
  [x: string]: ((...args: any[]) => any) | null;
4
5
  } | string[], {} & {}, {
5
6
  [x: number]: string;
6
7
  } | {}, true>)>;
7
8
  export default _default;
8
- export declare const Text: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
9
+ export declare const Default: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
9
10
  [x: string]: ((...args: any[]) => any) | null;
10
11
  } | string[], {} & {}, {
11
12
  [x: number]: string;
12
13
  } | {}, true>)>;
14
+ export declare const MiddleCrop: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
15
+ [x: string]: ((...args: any[]) => any) | null;
16
+ } | string[], {} & {}, {
17
+ [x: number]: string;
18
+ } | {}, true>)>;
19
+ export declare const TooFarLeft: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
20
+ [x: string]: ((...args: any[]) => any) | null;
21
+ } | string[], {} & {}, {
22
+ [x: number]: string;
23
+ } | {}, true>)>;
24
+ export declare const ComplexContainer: StoryFn<typeof OrText>;
@@ -6,22 +6,42 @@ declare const _default: import("vue").ComponentOptions<import("vue").default, im
6
6
  mainText: import("@vue/composition-api").ComputedRef<string>;
7
7
  restText: import("@vue/composition-api").ComputedRef<string>;
8
8
  }> & import("@vue/composition-api").Data, {}, {}, {
9
+ /**
10
+ * Text to crop.
11
+ */
9
12
  text: {
10
13
  type: StringConstructor;
11
14
  required: true;
12
15
  };
16
+ /**
17
+ * The index counted from the end of the string where ellipsis will be placed.
18
+ * Defines how many ending characters will remain visible.
19
+ * By default, ellipsis is placed in the end of the line.
20
+ *
21
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
22
+ */
13
23
  sliceIndex: {
14
24
  type: NumberConstructor;
15
- default: undefined;
25
+ default: number;
16
26
  };
17
27
  }, import("@vue/composition-api").ExtractPropTypes<{
28
+ /**
29
+ * Text to crop.
30
+ */
18
31
  text: {
19
32
  type: StringConstructor;
20
33
  required: true;
21
34
  };
35
+ /**
36
+ * The index counted from the end of the string where ellipsis will be placed.
37
+ * Defines how many ending characters will remain visible.
38
+ * By default, ellipsis is placed in the end of the line.
39
+ *
40
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
41
+ */
22
42
  sliceIndex: {
23
43
  type: NumberConstructor;
24
- default: undefined;
44
+ default: number;
25
45
  };
26
46
  }>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{
27
47
  text: string;
@@ -39,4 +59,9 @@ declare const _default: import("vue").ComponentOptions<import("vue").default, im
39
59
  } & {}, {
40
60
  sliceIndex: number;
41
61
  }, true>);
62
+ /**
63
+ * Use `OrText` component to crop un-wrapped single-line text with ellipsis inside narrow containers.
64
+ * Ellipsis can be placed in the end or in the middle of the text. Convenient for displaying long labels,
65
+ * that have same beginning and differ in the ending part.
66
+ */
42
67
  export default _default;
@@ -1,3 +1,3 @@
1
- export { _ as OrTextV3 } from '../../OrText-b12d0682.js';
1
+ export { _ as OrTextV3 } from '../../OrText-91d662a0.js';
2
2
  import 'vue-demi';
3
3
  import '../../normalize-component-6e8e3d80.js';
@@ -89,7 +89,7 @@ export { _ as OrTag } from './OrTag-c1fa6901.js';
89
89
  export { _ as OrTagV3, a as TagColor, T as TagVariant } from './OrTag-920c6371.js';
90
90
  export { _ as OrTeleport } from './OrTeleportVue2-8ef4ceca.js';
91
91
  export { _ as OrTeleportV3 } from './OrTeleport.vue2-fb92f29f.js';
92
- export { _ as OrTextV3 } from './OrText-b12d0682.js';
92
+ export { _ as OrTextV3 } from './OrText-91d662a0.js';
93
93
  export { _ as OrTextarea } from './OrTextarea-91a95068.js';
94
94
  export { _ as OrTextareaV3 } from './OrTextarea-373d0554.js';
95
95
  export { _ as OrTextbox, T as TextboxTypes } from './OrTextbox-2594c980.js';
@@ -17,16 +17,31 @@ const RestText = [
17
17
  // Layout
18
18
  'shrink'];
19
19
 
20
+ /**
21
+ * Use `OrText` component to crop un-wrapped single-line text with ellipsis inside narrow containers.
22
+ * Ellipsis can be placed in the end or in the middle of the text. Convenient for displaying long labels,
23
+ * that have same beginning and differ in the ending part.
24
+ */
20
25
  var script = defineComponent({
21
26
  name: 'OrText',
22
27
  props: {
28
+ /**
29
+ * Text to crop.
30
+ */
23
31
  text: {
24
32
  type: String,
25
33
  required: true
26
34
  },
35
+ /**
36
+ * The index counted from the end of the string where ellipsis will be placed.
37
+ * Defines how many ending characters will remain visible.
38
+ * By default, ellipsis is placed in the end of the line.
39
+ *
40
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
41
+ */
27
42
  sliceIndex: {
28
43
  type: Number,
29
- default: undefined
44
+ default: 0
30
45
  }
31
46
  },
32
47
  expose: ['root'],
@@ -37,15 +52,33 @@ var script = defineComponent({
37
52
  const rootStyles = computed(() => ['or-text', ...TextRoot]);
38
53
  const mainTextStyles = computed(() => [...MainText]);
39
54
  const restTextStyles = computed(() => [...RestText]);
55
+ /**
56
+ * Preserves whitespace at the last position as <code>&nbsp;</code>
57
+ * @param str A string to escape
58
+ */
59
+ const escapeLast = str => str && str.slice(0, -1) + '\xa0';
60
+ /**
61
+ * Preserves whitespace at the first position as <code>&nbsp;</code>
62
+ * @param str A string to escape
63
+ */
64
+ const escapeFirst = str => str && '\xa0' + str.slice(1);
40
65
  // State
41
66
  const mainText = computed(() => {
42
67
  if (props.sliceIndex) {
43
- return props.text.slice(0, Math.abs(props.sliceIndex) * -1);
68
+ let mainPart = props.text.slice(0, -Math.abs(props.sliceIndex));
69
+ if (mainPart[mainPart.length - 1] === ' ') {
70
+ mainPart = escapeLast(mainPart);
71
+ }
72
+ return mainPart;
44
73
  }
45
74
  return props.text;
46
75
  });
47
76
  const restText = computed(() => {
48
- return props.text.slice(mainText.value.length);
77
+ let restPart = props.text.slice(mainText.value.length);
78
+ if (restPart[0] === ' ') {
79
+ restPart = escapeFirst(restPart);
80
+ }
81
+ return restPart;
49
82
  });
50
83
  return {
51
84
  root,
@@ -86,7 +86,7 @@ export { s as OrTag } from '../OrTag-1b5e43fa.js';
86
86
  export { s as OrTagV3, a as TagColor, T as TagVariant } from '../OrTag-1d3fa09e.js';
87
87
  export { s as OrTeleport } from '../OrTeleportVue3-ad639f12.js';
88
88
  export { s as OrTeleportV3 } from '../OrTeleport.vue3-8099178c.js';
89
- export { s as OrTextV3 } from '../OrText-6b4f7cd1.js';
89
+ export { s as OrTextV3 } from '../OrText-a3b00048.js';
90
90
  export { s as OrTextarea } from '../OrTextarea-1f5c3be1.js';
91
91
  export { s as OrTextareaV3 } from '../OrTextarea-42d21f77.js';
92
92
  export { s as OrTextbox, T as TextboxTypes } from '../OrTextbox-2f33e9c3.js';
@@ -1,12 +1,24 @@
1
1
  import { Meta, StoryFn } from '@storybook/vue3';
2
+ import OrText from './OrText.vue';
2
3
  declare const _default: Meta<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
3
4
  [x: string]: ((...args: any[]) => any) | null;
4
5
  } | string[], {} & {}, {
5
6
  [x: number]: string;
6
7
  } | {}, true>)>;
7
8
  export default _default;
8
- export declare const Text: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
9
+ export declare const Default: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
9
10
  [x: string]: ((...args: any[]) => any) | null;
10
11
  } | string[], {} & {}, {
11
12
  [x: number]: string;
12
13
  } | {}, true>)>;
14
+ export declare const MiddleCrop: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
15
+ [x: string]: ((...args: any[]) => any) | null;
16
+ } | string[], {} & {}, {
17
+ [x: number]: string;
18
+ } | {}, true>)>;
19
+ export declare const TooFarLeft: StoryFn<import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<unknown>, import("@vue/composition-api").MethodOptions, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>, import("@vue/composition-api").ExtractPropTypes<import("@vue/composition-api").ComponentPropsOptions<import("@vue/composition-api").Data>>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{} & {}, import("@vue/composition-api").ShallowUnwrapRef<unknown>, unknown, import("@vue/composition-api").ComputedOptions, import("@vue/composition-api").MethodOptions, unknown, unknown, {
20
+ [x: string]: ((...args: any[]) => any) | null;
21
+ } | string[], {} & {}, {
22
+ [x: number]: string;
23
+ } | {}, true>)>;
24
+ export declare const ComplexContainer: StoryFn<typeof OrText>;
@@ -6,22 +6,42 @@ declare const _default: import("vue").ComponentOptions<import("vue").default, im
6
6
  mainText: import("@vue/composition-api").ComputedRef<string>;
7
7
  restText: import("@vue/composition-api").ComputedRef<string>;
8
8
  }> & import("@vue/composition-api").Data, {}, {}, {
9
+ /**
10
+ * Text to crop.
11
+ */
9
12
  text: {
10
13
  type: StringConstructor;
11
14
  required: true;
12
15
  };
16
+ /**
17
+ * The index counted from the end of the string where ellipsis will be placed.
18
+ * Defines how many ending characters will remain visible.
19
+ * By default, ellipsis is placed in the end of the line.
20
+ *
21
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
22
+ */
13
23
  sliceIndex: {
14
24
  type: NumberConstructor;
15
- default: undefined;
25
+ default: number;
16
26
  };
17
27
  }, import("@vue/composition-api").ExtractPropTypes<{
28
+ /**
29
+ * Text to crop.
30
+ */
18
31
  text: {
19
32
  type: StringConstructor;
20
33
  required: true;
21
34
  };
35
+ /**
36
+ * The index counted from the end of the string where ellipsis will be placed.
37
+ * Defines how many ending characters will remain visible.
38
+ * By default, ellipsis is placed in the end of the line.
39
+ *
40
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
41
+ */
22
42
  sliceIndex: {
23
43
  type: NumberConstructor;
24
- default: undefined;
44
+ default: number;
25
45
  };
26
46
  }>> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{
27
47
  text: string;
@@ -39,4 +59,9 @@ declare const _default: import("vue").ComponentOptions<import("vue").default, im
39
59
  } & {}, {
40
60
  sliceIndex: number;
41
61
  }, true>);
62
+ /**
63
+ * Use `OrText` component to crop un-wrapped single-line text with ellipsis inside narrow containers.
64
+ * Ellipsis can be placed in the end or in the middle of the text. Convenient for displaying long labels,
65
+ * that have same beginning and differ in the ending part.
66
+ */
42
67
  export default _default;
@@ -1,3 +1,3 @@
1
- export { s as OrTextV3 } from '../../OrText-6b4f7cd1.js';
1
+ export { s as OrTextV3 } from '../../OrText-a3b00048.js';
2
2
  import 'vue-demi';
3
3
  import 'vue';
@@ -86,7 +86,7 @@ export { s as OrTag } from './OrTag-1b5e43fa.js';
86
86
  export { s as OrTagV3, a as TagColor, T as TagVariant } from './OrTag-1d3fa09e.js';
87
87
  export { s as OrTeleport } from './OrTeleportVue3-ad639f12.js';
88
88
  export { s as OrTeleportV3 } from './OrTeleport.vue3-8099178c.js';
89
- export { s as OrTextV3 } from './OrText-6b4f7cd1.js';
89
+ export { s as OrTextV3 } from './OrText-a3b00048.js';
90
90
  export { s as OrTextarea } from './OrTextarea-1f5c3be1.js';
91
91
  export { s as OrTextareaV3 } from './OrTextarea-42d21f77.js';
92
92
  export { s as OrTextbox, T as TextboxTypes } from './OrTextbox-2f33e9c3.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/ui-components",
3
- "version": "2.74.2",
3
+ "version": "2.74.3-beta.2300.0",
4
4
  "description": "Vue components library for v2/3",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/auto/index.js",
@@ -124,6 +124,5 @@
124
124
  "default": "./dist/bundled/v3/components/*/index.js"
125
125
  },
126
126
  "./package.json": "./package.json"
127
- },
128
- "gitHead": "0210ab5e65f8f3a902ce53fb27c731832b042eef"
127
+ }
129
128
  }
@@ -34,13 +34,89 @@ const Template: StoryFn<typeof OrText> = (args) => ({
34
34
  },
35
35
 
36
36
  template: `
37
- <OrText v-bind="args" />
37
+ <div class="w-2/5 mx-auto px-md bg-surface-2 dark:bg-surface-2-dark">
38
+ <OrText v-bind="args" />
39
+ </div>
38
40
  `,
39
41
  });
40
42
 
41
- export const Text = Template.bind({});
42
-
43
- Text.args = {
43
+ export const Default = Template.bind({});
44
+ Default.args = {
44
45
  // Props
45
- text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
46
+ text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt \
47
+ ut labore et dolore magna aliqua.',
48
+ };
49
+
50
+ export const MiddleCrop = Template.bind({});
51
+ MiddleCrop.args = {
52
+ ...Default.args,
53
+ sliceIndex: 12,
54
+ };
55
+
56
+ export const TooFarLeft = Template.bind({});
57
+ TooFarLeft.args = {
58
+ ...Default.args,
59
+ sliceIndex: 120,
60
+ };
61
+ TooFarLeft.parameters = {
62
+ docs: {
63
+ description: {
64
+ story: 'Caution. If `sliceIndex` is greater than the visible part length, \
65
+ then beginning part with ellipsis is not displayed and ending part overflows the container.',
66
+ },
67
+ },
68
+ };
69
+
70
+ export const ComplexContainer: StoryFn<typeof OrText> = (args) => ({
71
+ components: {
72
+ OrText,
73
+ },
74
+
75
+ setup() {
76
+ return { args };
77
+ },
78
+
79
+ template: `
80
+ <h3 class="typography-headline-3 mb-md">Flex container side effect</h3>
81
+ <div class="w-[300px] flex bg-surface-2 dark:bg-surface-2-dark">
82
+ <!-- fixed part -->
83
+ <div class="w-[20px]" />
84
+ <!-- growing part -->
85
+ <div class="grow px-md">
86
+ <OrText v-bind="args" />
87
+ </div>
88
+ </div>
89
+ <h3 class="typography-headline-3 my-md">Solution with a wrapper</h3>
90
+ <div class="w-[300px] flex bg-surface-2 dark:bg-surface-2-dark">
91
+ <!-- fixed part -->
92
+ <div class="w-[20px]" />
93
+ <!-- growing part -->
94
+ <div class="grow px-md min-w-0">
95
+ <OrText v-bind="args" />
96
+ </div>
97
+ </div>
98
+ <h3 class="typography-headline-3 my-md">Solution without a wrapper</h3>
99
+ <div class="w-[300px] flex bg-surface-2 dark:bg-surface-2-dark">
100
+ <!-- fixed part -->
101
+ <div class="w-[20px]" />
102
+ <!-- growing part -->
103
+ <OrText v-bind="args" class="grow px-md min-w-0"/>
104
+ </div>
105
+ `,
106
+ });
107
+ ComplexContainer.storyName = 'Growing Flex Container';
108
+ ComplexContainer.args = {
109
+ ...Default.args,
110
+ sliceIndex: 12,
111
+ };
112
+ ComplexContainer.parameters = {
113
+ docs: {
114
+ description: {
115
+ story: 'In a special case when OrText is placed inside a variable width container,\
116
+ such as a flexbox growing block, or when it is itself a growing flexbox item,\
117
+ there is a problem for a browser to proper calculate the cropping position.\
118
+ As a solution place a `min-width: 0;` style (tailwind class `min-w-0`)\
119
+ to the growing item - container or the OrText itself.',
120
+ },
121
+ },
46
122
  };
@@ -17,18 +17,33 @@
17
17
  import { computed, defineComponent, ref } from 'vue-demi';
18
18
  import { MainText, RestText, TextRoot } from './styles';
19
19
 
20
+ /**
21
+ * Use `OrText` component to crop un-wrapped single-line text with ellipsis inside narrow containers.
22
+ * Ellipsis can be placed in the end or in the middle of the text. Convenient for displaying long labels,
23
+ * that have same beginning and differ in the ending part.
24
+ */
20
25
  export default defineComponent({
21
26
  name: 'OrText',
22
27
 
23
28
  props: {
29
+ /**
30
+ * Text to crop.
31
+ */
24
32
  text: {
25
33
  type: String,
26
34
  required: true,
27
35
  },
28
36
 
37
+ /**
38
+ * The index counted from the end of the string where ellipsis will be placed.
39
+ * Defines how many ending characters will remain visible.
40
+ * By default, ellipsis is placed in the end of the line.
41
+ *
42
+ * Note: Negative values behave same as corresponding positives still counting from the end of the line.
43
+ */
29
44
  sliceIndex: {
30
45
  type: Number,
31
- default: undefined,
46
+ default: 0,
32
47
  },
33
48
  },
34
49
 
@@ -54,17 +69,36 @@ export default defineComponent({
54
69
  ...RestText,
55
70
  ]);
56
71
 
72
+ /**
73
+ * Preserves whitespace at the last position as <code>&nbsp;</code>
74
+ * @param str A string to escape
75
+ */
76
+ const escapeLast = (str: string): string => str && (str.slice(0, -1) + '\xa0');
77
+ /**
78
+ * Preserves whitespace at the first position as <code>&nbsp;</code>
79
+ * @param str A string to escape
80
+ */
81
+ const escapeFirst = (str: string): string => str && ('\xa0' + str.slice(1));
82
+
57
83
  // State
58
84
  const mainText = computed(() => {
59
85
  if (props.sliceIndex) {
60
- return props.text.slice(0, Math.abs(props.sliceIndex) * -1);
86
+ let mainPart = props.text.slice(0, -Math.abs(props.sliceIndex));
87
+ if (mainPart[mainPart.length - 1] === ' ') {
88
+ mainPart = escapeLast(mainPart);
89
+ }
90
+ return mainPart;
61
91
  }
62
92
 
63
93
  return props.text;
64
94
  });
65
95
 
66
96
  const restText = computed(() => {
67
- return props.text.slice(mainText.value.length);
97
+ let restPart = props.text.slice(mainText.value.length);
98
+ if (restPart[0] === ' ') {
99
+ restPart = escapeFirst(restPart);
100
+ }
101
+ return restPart;
68
102
  });
69
103
 
70
104
  return {
@@ -1,60 +0,0 @@
1
- import { defineComponent, ref, computed } from 'vue';
2
-
3
- const TextRoot = [
4
- // Layout
5
- 'inline-flex',
6
- // Box
7
- 'max-w-full',
8
- // Typography
9
- 'whitespace-nowrap'];
10
- const MainText = [
11
- // Layout
12
- 'overflow-hidden',
13
- // Typography
14
- 'text-ellipsis'];
15
- const RestText = [
16
- // Layout
17
- 'shrink'];
18
-
19
- var script = defineComponent({
20
- name: 'OrText',
21
- props: {
22
- text: {
23
- type: String,
24
- required: true
25
- },
26
- sliceIndex: {
27
- type: Number,
28
- default: undefined
29
- }
30
- },
31
- expose: ['root'],
32
- setup(props) {
33
- // Refs
34
- const root = ref();
35
- // Styles
36
- const rootStyles = computed(() => ['or-text', ...TextRoot]);
37
- const mainTextStyles = computed(() => [...MainText]);
38
- const restTextStyles = computed(() => [...RestText]);
39
- // State
40
- const mainText = computed(() => {
41
- if (props.sliceIndex) {
42
- return props.text.slice(0, Math.abs(props.sliceIndex) * -1);
43
- }
44
- return props.text;
45
- });
46
- const restText = computed(() => {
47
- return props.text.slice(mainText.value.length);
48
- });
49
- return {
50
- root,
51
- rootStyles,
52
- mainTextStyles,
53
- restTextStyles,
54
- mainText,
55
- restText
56
- };
57
- }
58
- });
59
-
60
- export { script as s };