mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
feat(truncate): add text truncation component and action
This commit is contained in:
parent
735c6a7f7e
commit
a51c300a79
13 changed files with 161 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"total": 157,
|
||||
"total": 158,
|
||||
"components": [
|
||||
{
|
||||
"moduleName": "Accordion",
|
||||
|
@ -10664,6 +10664,25 @@
|
|||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "button" }
|
||||
},
|
||||
{
|
||||
"moduleName": "Truncate",
|
||||
"filePath": "src/Truncate/Truncate.svelte",
|
||||
"props": [
|
||||
{
|
||||
"name": "direction",
|
||||
"kind": "let",
|
||||
"type": "\"end\" | \"front\"",
|
||||
"value": "\"end\"",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
}
|
||||
],
|
||||
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
|
||||
"events": [],
|
||||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "div" }
|
||||
},
|
||||
{
|
||||
"moduleName": "UnorderedList",
|
||||
"filePath": "src/UnorderedList/UnorderedList.svelte",
|
||||
|
|
37
docs/src/pages/components/Truncate.svx
Normal file
37
docs/src/pages/components/Truncate.svx
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
<script>
|
||||
import { Truncate } from "carbon-components-svelte";
|
||||
import { truncate } from "carbon-components-svelte/actions";
|
||||
import Preview from "../../components/Preview.svelte";
|
||||
</script>
|
||||
|
||||
This is a utility component that wraps the `.bx--text-truncate--*` CSS selector from `carbon-components` for single line text truncation.
|
||||
|
||||
### Default
|
||||
|
||||
By default, text will be clamped at the end of the line. Text is wrapped with a paragraph (`p`) element. Use the [truncate action](#usetruncate) to truncate text in other elements.
|
||||
|
||||
<Truncate>
|
||||
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
|
||||
</Truncate>
|
||||
|
||||
### Direction (front)
|
||||
|
||||
Set `direction` to `"front"` to clamp the text from the front.
|
||||
|
||||
<Truncate direction="front">
|
||||
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
|
||||
</Truncate>
|
||||
|
||||
### use:truncate
|
||||
|
||||
The `truncate` action can be used on other HTML elements.
|
||||
|
||||
Import path: `import { truncate } from "carbon-components-svelte/actions";`
|
||||
|
||||
<h4 use:truncate>
|
||||
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
|
||||
</h4>
|
||||
<h4 use:truncate={{ direction: "front" }}>
|
||||
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
|
||||
</h4>
|
|
@ -38,6 +38,9 @@ function createImports(source) {
|
|||
const ccs_imports = Array.from(inlineComponents.keys());
|
||||
const icon_imports = Array.from(icons.keys());
|
||||
|
||||
if (ccs_imports.length === 0) return "";
|
||||
// TODO: determine if action is used, and generate import accordingly
|
||||
|
||||
return `
|
||||
<script>
|
||||
import {${ccs_imports.join(",")}} from "carbon-components-svelte";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue