Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(NcEllipsisedOption): add docs #5663

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion src/components/NcEllipsisedOption/NcEllipsisedOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,69 @@
-
-->

<docs>
A component to display a long text with highlight support in one line truncated with ellipsis in the end but keeping up to 10 last characters.

It is supposed to be used as an `NcSelect`'s option in first place.

### General usage

```vue
<template>
<div>
<h4>Plain text</h4>
<p>{{ text }}</p>

<h4>Truncated text with <code>text-overflow: ellipsis</code></h4>
<p style="text-overflow: ellipsis; overflow: hidden; white-space: pre;">{{ text }}</p>

<h4>NcEllipsisedOption searching for "Nineteen"</h4>
<NcEllipsisedOption :name="text" :search="search" />
</div>
</template>

<script>
export default {
data() {
return {
text: 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twenty',
search: 'Nineteen',
}
},
}
</script>
```

### Usage in `NcSelect`

```vue
<template>
<NcSelect v-model="selected" :options="options">
<template #option="option">
<NcEllipsisedOption :name="option.label" />
</template>
<template #selected-option="selectedOption">
<NcEllipsisedOption :name="selectedOption.label" />
</template>
</NcSelect>
</template>

<script>
export default {
data() {
return {
options: [
'Option 1 - a short opt.',
'Option 2 - a very very very very long opt.',
].map((label) => ({ label })),
selected: '',
}
},
}
</script>
```
</docs>

<template>
<span class="name-parts" :title="name">
<NcHighlight class="name-parts__first"
Expand All @@ -45,11 +108,16 @@ export default {
},

props: {
/**
* The text to be display in one line. If it is longer than 10 characters, it is be truncated with ellipsis in the end but keeping up to 10 last characters to fit the parent container.
*/
name: {
type: String,
default: '',
},

/**
* The search value to highlight in the text
*/
search: {
type: String,
default: '',
Expand Down
Loading