@ctrliq/quantic-components 1.63.6 → 1.64.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,19 @@
1
+ import { QuanticElement } from '../shared/quantic-element';
2
+ import type { ComponentMeta } from '../shared/meta.types';
3
+ import { TooltipPlacement } from '../tooltip/index.constants';
4
+ export { TooltipPlacement } from '../tooltip/index.constants';
5
+ export declare class Truncate extends QuanticElement {
6
+ static meta: ComponentMeta;
7
+ value: string;
8
+ maxLines: number;
9
+ placement: TooltipPlacement;
10
+ private textEl?;
11
+ private observer?;
12
+ private isTruncated;
13
+ static styles: import("lit").CSSResult;
14
+ firstUpdated(): void;
15
+ updated(changed: Map<string, unknown>): void;
16
+ disconnectedCallback(): void;
17
+ private checkTruncation;
18
+ render(): import("lit-html").TemplateResult<1>;
19
+ }
@@ -0,0 +1,134 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { css, html, nothing } from 'lit';
8
+ import { state, query } from 'lit/decorators.js';
9
+ import { styleMap } from 'lit/directives/style-map.js';
10
+ import { classMap } from 'lit/directives/class-map.js';
11
+ import { quanticElement, QuanticElement } from '../shared/quantic-element';
12
+ import { prop } from '../shared/component-meta.decorators';
13
+ import { TooltipPlacement } from '../tooltip/index.constants';
14
+ import { Tooltip } from '../tooltip';
15
+ export { TooltipPlacement } from '../tooltip/index.constants';
16
+ Tooltip.ensureDefined();
17
+ let Truncate = class Truncate extends QuanticElement {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.value = '';
21
+ this.maxLines = 1;
22
+ this.placement = TooltipPlacement.Top;
23
+ this.isTruncated = false;
24
+ }
25
+ firstUpdated() {
26
+ this.observer = new ResizeObserver(() => this.checkTruncation());
27
+ this.observer.observe(this);
28
+ this.checkTruncation();
29
+ }
30
+ updated(changed) {
31
+ if (changed.has('maxLines') || changed.has('value')) {
32
+ this.checkTruncation();
33
+ }
34
+ }
35
+ disconnectedCallback() {
36
+ super.disconnectedCallback();
37
+ this.observer?.disconnect();
38
+ }
39
+ checkTruncation() {
40
+ if (!this.textEl)
41
+ return;
42
+ const isTruncated = this.maxLines > 1
43
+ ? this.textEl.scrollHeight > this.textEl.clientHeight
44
+ : this.textEl.scrollWidth > this.textEl.clientWidth;
45
+ if (isTruncated !== this.isTruncated) {
46
+ this.isTruncated = isTruncated;
47
+ }
48
+ }
49
+ render() {
50
+ const text = html `
51
+ <div
52
+ class=${classMap({ text: true, 'text--multiline': this.maxLines > 1 })}
53
+ style=${styleMap({ '--truncate-max-lines': String(this.maxLines) })}
54
+ tabindex=${this.isTruncated ? '0' : nothing}
55
+ >
56
+ ${this.value}
57
+ </div>
58
+ `;
59
+ return this.isTruncated
60
+ ? html `
61
+ <quantic-tooltip placement=${this.placement}>
62
+ ${text}
63
+ <span slot="content">${this.value}</span>
64
+ </quantic-tooltip>
65
+ `
66
+ : text;
67
+ }
68
+ };
69
+ Truncate.meta = {
70
+ tag: 'quantic-truncate',
71
+ description: 'Renders text with ellipsis overflow. ' +
72
+ 'A tooltip revealing the full value appears on hover or keyboard focus when the text is actually truncated.',
73
+ category: 'display',
74
+ relatedTo: ['quantic-tooltip'],
75
+ };
76
+ Truncate.styles = css `
77
+ :host {
78
+ display: block;
79
+ min-width: 0;
80
+ }
81
+
82
+ quantic-tooltip {
83
+ display: block;
84
+ min-width: 0;
85
+ }
86
+
87
+ .text {
88
+ overflow: hidden;
89
+ text-overflow: ellipsis;
90
+ white-space: nowrap;
91
+ min-width: 0;
92
+ }
93
+
94
+ .text--multiline {
95
+ display: -webkit-box;
96
+ -webkit-box-orient: vertical;
97
+ -webkit-line-clamp: var(--truncate-max-lines);
98
+ line-clamp: var(--truncate-max-lines);
99
+ white-space: normal;
100
+ }
101
+ `;
102
+ __decorate([
103
+ prop({
104
+ type: 'string',
105
+ default: '',
106
+ description: 'Text to display and show in the tooltip when truncated.',
107
+ })
108
+ ], Truncate.prototype, "value", void 0);
109
+ __decorate([
110
+ prop({
111
+ type: 'number',
112
+ attribute: 'max-lines',
113
+ default: '1',
114
+ description: 'Maximum number of visible lines before truncating. Defaults to 1 (single-line).',
115
+ })
116
+ ], Truncate.prototype, "maxLines", void 0);
117
+ __decorate([
118
+ prop({
119
+ type: 'TooltipPlacement',
120
+ options: Object.values(TooltipPlacement),
121
+ default: TooltipPlacement.Top,
122
+ description: 'Preferred tooltip placement relative to the text.',
123
+ })
124
+ ], Truncate.prototype, "placement", void 0);
125
+ __decorate([
126
+ query('.text')
127
+ ], Truncate.prototype, "textEl", void 0);
128
+ __decorate([
129
+ state()
130
+ ], Truncate.prototype, "isTruncated", void 0);
131
+ Truncate = __decorate([
132
+ quanticElement('quantic-truncate')
133
+ ], Truncate);
134
+ export { Truncate };
@@ -0,0 +1,24 @@
1
+ import { TooltipPlacement } from './index';
2
+ interface Args {
3
+ value: string;
4
+ maxLines: number;
5
+ placement: TooltipPlacement;
6
+ }
7
+ declare const _default: {
8
+ title: string;
9
+ component: string;
10
+ tags: string[];
11
+ argTypes: {
12
+ placement: {
13
+ control: {
14
+ type: string;
15
+ };
16
+ options: ("top" | "right" | "bottom" | "left" | "top-end" | "top-start" | "right-end" | "right-start" | "bottom-end" | "bottom-start" | "left-end" | "left-start")[];
17
+ };
18
+ };
19
+ };
20
+ export default _default;
21
+ export declare const Default: import("../shared/story").StoryObject<Args>;
22
+ export declare const NotTruncated: import("../shared/story").StoryObject<Args>;
23
+ export declare const Multiline: import("../shared/story").StoryObject<Args>;
24
+ export declare const TooltipBottom: import("../shared/story").StoryObject<Args>;
@@ -0,0 +1,26 @@
1
+ import { story } from '../shared/story';
2
+ import { TooltipPlacement } from './index';
3
+ export default {
4
+ title: 'Components/Display/Truncate',
5
+ component: 'quantic-truncate',
6
+ tags: ['autodocs'],
7
+ argTypes: {
8
+ placement: {
9
+ control: { type: 'select' },
10
+ options: Object.values(TooltipPlacement),
11
+ },
12
+ },
13
+ };
14
+ const long = 'This is a very long string that will overflow its container and trigger the tooltip on hover.';
15
+ const multilineText = 'Design systems are a collection of reusable components, guided by clear standards, that can be assembled to build any number of applications. They are the single source of truth for a product\'s design language and serve as a foundation for consistent, high-quality experiences.';
16
+ const base = story({
17
+ args: { value: long, maxLines: 1, placement: TooltipPlacement.Top },
18
+ }).render(({ html, value, maxLines, placement }) => html `
19
+ <div style="width: 300px;">
20
+ <quantic-truncate value=${value} max-lines=${maxLines} placement=${placement}></quantic-truncate>
21
+ </div>
22
+ `);
23
+ export const Default = base;
24
+ export const NotTruncated = base.override({ value: 'Short text' });
25
+ export const Multiline = base.override({ value: multilineText, maxLines: 3 });
26
+ export const TooltipBottom = base.override({ placement: TooltipPlacement.Bottom });
@@ -39,3 +39,4 @@ export * from './textarea';
39
39
  export * from './toast';
40
40
  export * from './toggle';
41
41
  export * from './tooltip';
42
+ export * from './truncate';
@@ -0,0 +1,19 @@
1
+ import { QuanticElement } from '../shared/quantic-element';
2
+ import type { ComponentMeta } from '../shared/meta.types';
3
+ import { TooltipPlacement } from '../tooltip/index.constants';
4
+ export { TooltipPlacement } from '../tooltip/index.constants';
5
+ export declare class Truncate extends QuanticElement {
6
+ static meta: ComponentMeta;
7
+ value: string;
8
+ maxLines: number;
9
+ placement: TooltipPlacement;
10
+ private textEl?;
11
+ private observer?;
12
+ private isTruncated;
13
+ static styles: import("lit").CSSResult;
14
+ firstUpdated(): void;
15
+ updated(changed: Map<string, unknown>): void;
16
+ disconnectedCallback(): void;
17
+ private checkTruncation;
18
+ render(): import("lit-html").TemplateResult<1>;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { TooltipPlacement } from './index';
2
+ interface Args {
3
+ value: string;
4
+ maxLines: number;
5
+ placement: TooltipPlacement;
6
+ }
7
+ declare const _default: {
8
+ title: string;
9
+ component: string;
10
+ tags: string[];
11
+ argTypes: {
12
+ placement: {
13
+ control: {
14
+ type: string;
15
+ };
16
+ options: ("top" | "right" | "bottom" | "left" | "top-end" | "top-start" | "right-end" | "right-start" | "bottom-end" | "bottom-start" | "left-end" | "left-start")[];
17
+ };
18
+ };
19
+ };
20
+ export default _default;
21
+ export declare const Default: import("../shared/story").StoryObject<Args>;
22
+ export declare const NotTruncated: import("../shared/story").StoryObject<Args>;
23
+ export declare const Multiline: import("../shared/story").StoryObject<Args>;
24
+ export declare const TooltipBottom: import("../shared/story").StoryObject<Args>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrliq/quantic-components",
3
- "version": "1.63.6",
3
+ "version": "1.64.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "exports": {