Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react-vite';

import BasicUsageExample from './examples/basic_usage';
import FilterTriggerExample from './examples/filter-trigger';
import MultipleUseExample from './examples/multiple_use';
import NoHintWithMultilineExample from './examples/no_hint_with_multiline';
import WithRequiredLastSymbolsExample from './examples/with_required_last_symbols';
Expand All @@ -18,6 +19,10 @@ export const MultipleUse: StoryObj = {
render: MultipleUseExample,
};

export const FilterTrigger: StoryObj = {
render: FilterTriggerExample,
};

export const NoHintWithMultiline: StoryObj = {
render: NoHintWithMultilineExample,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { FilterTrigger } from '@semcore/ui/base-trigger';
import Select from '@semcore/ui/select';
import React from 'react';

const Demo = () => {
const [material, setMaterial] = React.useState([]);

return (
<>
<Select onChange={setMaterial} multiselect>
<Select.Trigger
tag={FilterTrigger}
placeholder='Material'
aria-label='Material'
>
<FilterTrigger.Text
wMax={80}
ellipsis={{ cropPosition: 'middle' }}
key={material.length}
>
<span aria-hidden='true'>Material: </span>
{material.length === 1 ? material : `${material.length} selected`}
</FilterTrigger.Text>
</Select.Trigger>

<Select.Menu aria-label='Material'>
{materials.map((option, idx) => (
<Select.Option value={option} key={idx}>
<Select.Option.Checkbox />
{option}
</Select.Option>
))}
</Select.Menu>
</Select>
</>
);
};

const materials = ['Glass', 'Metal', 'Paper', 'Wood'];

export default Demo;
20 changes: 20 additions & 0 deletions website/docs/utils/ellipsis/ellipsis-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ You can truncate paragraphs of text with ellipsis using the `maxLine` property.

Note that `maxLine` can only be used with `cropPosition: end`, and the hint is automatically disabled in this case.

To enable hint for cropped multiline text, set some `hintProps` or just enable it via `hintProps={true}`.

::: sandbox

<script lang="tsx">
Expand All @@ -85,3 +87,21 @@ You can customize the hint that appears on hover/focus by using the `hintProps`
</script>

:::

## FilterTrigger (dynamic children)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyabrower I thought it will be more clear if we make a separate section out of it and add an example, if you don't mind

left your original text, just with some slight fixes


Due to performance considerations, we don't observe changes in the `Text` children property. So, if you have some dynamically changing children in the `Text` component, you should set `observerChildrenMutations={true}` in the ellipsis settings.

Alternatively, you can set a unique `key` on the `Text`, depending on the children content.

::: tip
For some reason, only setting the `key` property works for `FilterTrigger.Text` right now.
:::

::: sandbox

<script lang="tsx">
export Demo from 'stories/components/base-components/ellipsis/docs/examples/filter-trigger.tsx';
</script>

:::
Loading