-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/1150-GridTable' into fea…
…ture/1507-grid-apply-tokens
- Loading branch information
Showing
29 changed files
with
383 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@sl-design-system/grid': patch | ||
--- | ||
|
||
Add `ellipsizeText` property to grid and column | ||
|
||
When set on either `<sl-grid>` or `<sl-grid-column>` (or any of their variants), the `ellipsizeText` property | ||
will render the table data using the `<sl-ellipsize-text>` component, which truncates text with an ellipsis when it | ||
overflows its container. This is useful for tables with long text that would otherwise cause row height to grow. | ||
The component also automatically adds a tooltip to the truncated text so that it can still be viewed. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sl-design-system/combobox': patch | ||
--- | ||
|
||
Hide the placeholder when there is a selection in multiple mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sl-design-system/ellipsize-text': patch | ||
--- | ||
|
||
New utility `<sl-ellipsize-text>` component |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@sl-design-system/combobox': patch | ||
'@sl-design-system/emoji': patch | ||
'@sl-design-system/listbox': patch | ||
'@sl-design-system/panel': patch | ||
'@sl-design-system/search-field': patch | ||
'@sl-design-system/tool-bar': patch | ||
--- | ||
|
||
Fix missing types in NPM package |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/ellipsize-text.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@sl-design-system/ellipsize-text", | ||
"version": "0.0.0", | ||
"description": "Utility component that ellipsizes text if it doesn't fit", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"registry": "https://npm.pkg.github.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sl-design-system/components.git", | ||
"directory": "packages/components/ellipsize-text" | ||
}, | ||
"homepage": "https://sanomalearning.design/components/ellipsize-text", | ||
"bugs": { | ||
"url": "https://github.com/sl-design-system/components/issues" | ||
}, | ||
"type": "module", | ||
"main": "./index.js", | ||
"module": "./index.js", | ||
"types": "./index.d.ts", | ||
"customElements": "custom-elements.json", | ||
"exports": { | ||
".": "./index.js", | ||
"./package.json": "./package.json", | ||
"./register.js": "./register.js" | ||
}, | ||
"files": [ | ||
"**/*.d.ts", | ||
"**/*.js", | ||
"**/*.js.map", | ||
"custom-elements.json" | ||
], | ||
"sideEffects": [ | ||
"register.js" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: run tests from monorepo root.\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@sl-design-system/tooltip": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@open-wc/scoped-elements": "^3.0.5" | ||
}, | ||
"peerDependencies": { | ||
"@open-wc/scoped-elements": "^3.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { EllipsizeText } from './src/ellipsize-text.js'; | ||
|
||
customElements.define('sl-ellipsize-text', EllipsizeText); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
:host { | ||
display: block; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/components/ellipsize-text/src/ellipsize-text.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { expect, fixture } from '@open-wc/testing'; | ||
import { html } from 'lit'; | ||
import '../register.js'; | ||
import { type EllipsizeText } from './ellipsize-text.js'; | ||
|
||
describe('sl-ellipsize-text', () => { | ||
let el: EllipsizeText; | ||
|
||
beforeEach(async () => { | ||
el = await fixture(html`<sl-ellipsize-text>This is a long text that should be truncated</sl-ellipsize-text>`); | ||
}); | ||
|
||
it('should render a slot with the text', () => { | ||
const slot = el.renderRoot.querySelector('slot'); | ||
|
||
expect(slot).to.exist; | ||
expect( | ||
slot | ||
?.assignedNodes() | ||
.map(node => node.textContent?.trim()) | ||
.join('') | ||
).to.equal('This is a long text that should be truncated'); | ||
}); | ||
|
||
it('should not have a tooltip by default', () => { | ||
expect(el).not.to.have.attribute('aria-describedby'); | ||
}); | ||
|
||
describe('tooltip', () => { | ||
beforeEach(async () => { | ||
el.style.width = '100px'; | ||
|
||
// Wait for the resize observer to trigger | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
||
// Trigger a focus event to create the tooltip | ||
el.dispatchEvent(new Event('focusin')); | ||
}); | ||
|
||
it('should have a tooltip when there is not enough space', () => { | ||
const tooltip = el.nextElementSibling; | ||
|
||
expect(tooltip).to.exist; | ||
expect(tooltip).to.match('sl-tooltip'); | ||
expect(el).to.have.attribute('aria-describedby', tooltip?.id); | ||
}); | ||
|
||
it('should remove the tooltip when the element is removed from the DOM', () => { | ||
el.remove(); | ||
|
||
expect(document.querySelector('sl-tooltip')).not.to.exist; | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/components/ellipsize-text/src/ellipsize-text.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type Meta, type StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
import '../register.js'; | ||
|
||
type Props = { text: string; width: number }; | ||
type Story = StoryObj<Props>; | ||
|
||
export default { | ||
title: 'Utilities/Ellipsize Text', | ||
tags: ['draft'], | ||
render: ({ text, width }) => html`<sl-ellipsize-text style="width: ${width}px">${text}</sl-ellipsize-text>` | ||
} satisfies Meta<Props>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
width: 200, | ||
text: 'This is a long text that should be truncated' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { type ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js'; | ||
import { Tooltip } from '@sl-design-system/tooltip'; | ||
import { type CSSResultGroup, LitElement, type TemplateResult, html } from 'lit'; | ||
import styles from './ellipsize-text.scss.js'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'sl-ellipsize-text': EllipsizeText; | ||
} | ||
} | ||
|
||
/** | ||
* Small utility component to add ellipsis to text that overflows | ||
* its container. It also adds a tooltip with the full text. | ||
*/ | ||
export class EllipsizeText extends ScopedElementsMixin(LitElement) { | ||
/** @internal */ | ||
static get scopedElements(): ScopedElementsMap { | ||
return { | ||
'sl-tooltip': Tooltip | ||
}; | ||
} | ||
|
||
/** @internal */ | ||
static override styles: CSSResultGroup = styles; | ||
|
||
/** Observe size changes. */ | ||
#observer = new ResizeObserver(() => this.#onResize()); | ||
|
||
/** The lazy tooltip. */ | ||
#tooltip?: Tooltip | (() => void); | ||
|
||
override connectedCallback(): void { | ||
super.connectedCallback(); | ||
|
||
this.#observer.observe(this); | ||
} | ||
|
||
override disconnectedCallback(): void { | ||
this.#observer.disconnect(); | ||
|
||
if (this.#tooltip instanceof Tooltip) { | ||
this.#tooltip.remove(); | ||
} else if (this.#tooltip) { | ||
this.#tooltip(); | ||
} | ||
|
||
this.#tooltip = undefined; | ||
|
||
super.disconnectedCallback(); | ||
} | ||
|
||
override render(): TemplateResult { | ||
return html`<slot></slot>`; | ||
} | ||
|
||
#onResize(): void { | ||
if (this.offsetWidth < this.scrollWidth) { | ||
this.#tooltip ||= Tooltip.lazy( | ||
this, | ||
tooltip => { | ||
this.#tooltip = tooltip; | ||
tooltip.position = 'bottom'; | ||
tooltip.textContent = this.textContent?.trim() || ''; | ||
}, | ||
{ context: this.shadowRoot! } | ||
); | ||
} else if (this.#tooltip instanceof Tooltip) { | ||
this.removeAttribute('aria-describedby'); | ||
|
||
this.#tooltip.remove(); | ||
this.#tooltip = undefined; | ||
} else if (this.#tooltip) { | ||
this.#tooltip(); | ||
this.#tooltip = undefined; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "./" | ||
}, | ||
"include": ["index.ts", "register.ts", "src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.