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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 26 additions & 2 deletions semcore/tag/src/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ class RootTag extends Component<
const isInteractiveView = !disabled && interactive;
const isInteractive = !disabled && interactive;

// By default, Tag.Text has an enabled ellipsis, but to use tags inside Input.Tags, we need to wrap the content without an ellipsis.
const onlyTextContent = isAdvanceMode(
Children,
[
'InputTags.Tag.Text.Content',
],
true,
);

// We shouldn't wrap in text if it has Circle or Addon
const hasAddonOrCircle = isAdvanceMode(
Children,
[
'InputTags.Tag.Circle',
'InputTags.Tag.Addon',
],
true,
);

const advancedMode = onlyTextContent || hasAddonOrCircle;

return sstyled(styles)(
<STag
render={Box}
Expand All @@ -100,7 +121,9 @@ class RootTag extends Component<
ref={this.tagRef}
>
{addonLeft ? <Tag.Addon tag={addonLeft} /> : null}
{addonTextChildren(Children, Tag.Text, [Tag.Addon, TagContainer.Circle])}
{advancedMode
? (hasAddonOrCircle ? <Children /> : <Tag.Text ellipsis={false}><Children /></Tag.Text>)
: addonTextChildren(Children, Tag.Text, [Tag.Addon, TagContainer.Circle])}
{addonRight ? <Tag.Addon tag={addonRight} /> : null}
</STag>,
);
Expand Down Expand Up @@ -315,12 +338,13 @@ function Text(
props: Intergalactic.InternalTypings.InferChildComponentProps<NSTag.Text.Component, typeof RootTag, 'Text'>,
) {
const SText = Root;
const { styles, tagRef } = props;
const { styles, tagRef, ellipsis = true } = props;

return sstyled(styles)(
<>
<SText
render={TypographyText}
ellipsis={ellipsis}
hint:triggerRef={tagRef}
/>
</>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flex, type EllipsisSettings } from '@semcore/ui/base-components';
import { Flex } from '@semcore/ui/base-components';
import type { InputTagsProps, InputTagsValueProps } from '@semcore/ui/input-tags';
import InputTags from '@semcore/ui/input-tags';
import { Text } from '@semcore/ui/typography';
Expand Down
46 changes: 42 additions & 4 deletions stories/components/input-tags/tests/examples/tags-with-addons.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import Check from '@semcore/icon/Check/m';
import Edit from '@semcore/icon/Edit/m';
import { Box, Flex } from '@semcore/ui/base-components';
import { Flex, type BoxProps } from '@semcore/ui/base-components';
import InputTags from '@semcore/ui/input-tags';
import type { InputTagsTagProps } from '@semcore/ui/input-tags';
import React from 'react';

type ExampleInputTagsProps = InputTagsTagProps;
type ExampleInputTagsProps = InputTagsTagProps & {
textContentWidth?: BoxProps['w'];
ellipsis?: boolean;
};

const Demo = (props: ExampleInputTagsProps) => {
const textContentProps = props.ellipsis === undefined
? { w: props.textContentWidth }
: { w: props.textContentWidth, ellipsis: props.ellipsis };

return (
<Flex direction='column' gap={2}>
<Flex direction='column' gap={2} data-testid='normal-state' w={450}>
Expand All @@ -24,7 +31,9 @@ const Demo = (props: ExampleInputTagsProps) => {
<InputTags.Tag.Addon>
<Check />
</InputTags.Tag.Addon>
<InputTags.Tag.Text.Content>Text and addon</InputTags.Tag.Text.Content>
<InputTags.Tag.Text.Content {...textContentProps}>
Text and addon with a very long label that should be truncated by default
</InputTags.Tag.Text.Content>
</InputTags.Tag.Text>

</InputTags.Tag>
Expand Down Expand Up @@ -64,7 +73,34 @@ const Demo = (props: ExampleInputTagsProps) => {
<InputTags.Tag.Addon>
<Check />
</InputTags.Tag.Addon>
<InputTags.Tag.Text.Content>Circle addon text and close </InputTags.Tag.Text.Content>
<InputTags.Tag.Text.Content {...textContentProps}>
Circle addon text and close with a very long label
</InputTags.Tag.Text.Content>
</InputTags.Tag.Text>
<InputTags.Tag.Close />
</InputTags.Tag>

<InputTags.Tag
size={props.size}
theme={props.theme}
disabled={props.disabled}

interactive={props.interactive}

color={props.color}
>
<InputTags.Tag.Text>
<InputTags.Tag.Circle
style={{
background: '#2595e4',
}}
/>
<InputTags.Tag.Addon>
<Check />
</InputTags.Tag.Addon>
<InputTags.Tag.Text.Content>
Circle addon text and close
</InputTags.Tag.Text.Content>
</InputTags.Tag.Text>
<InputTags.Tag.Close />
</InputTags.Tag>
Expand Down Expand Up @@ -116,6 +152,8 @@ export const defaultPropsEmail: ExampleInputTagsProps = {
addonLeft: undefined,
interactive: undefined,
color: 'gray-500',
textContentWidth: 140,
ellipsis: undefined,
};

Demo.defaultProps = defaultPropsEmail;
Expand Down
12 changes: 12 additions & 0 deletions stories/components/input-tags/tests/input-tags.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ export const TagsWithAddons: StoryObj<typeof defaultPropsEmail> = {
control: { type: 'select' },
options: ['gray-500', 'blue-500', 'green-500', 'salad-500', 'orange-500', 'yellow-500', 'grredeen-500', 'pink-500', 'violet-500', 'white-500'],
},
textContentWidth: {
control: { type: 'number' },
},
ellipsis: {
control: { type: 'select' },
options: ['default', 'enabled', 'disabled'],
mapping: {
default: undefined,
enabled: true,
disabled: false,
},
},
},
args: defaultPropsEmail,
};
2 changes: 1 addition & 1 deletion stories/components/tag/docs/examples/editing_tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Demo = () => {
<>
<InlineEdit editable={editable} onEditableChange={setEditable}>
<InlineEdit.View tag={Tag} interactive size='l'>
<Tag.Text>{value}</Tag.Text>
<Tag.Text ellipsis:observeChildrenMutations>{value}</Tag.Text>
</InlineEdit.View>
<InlineEdit.Edit>
<InlineInput onConfirm={handleValue} onCancel={resetEditable}>
Expand Down
8 changes: 4 additions & 4 deletions stories/components/tag/tests/examples/tag-with-ellipsis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const Demo = () => {
return (
<Flex direction='column' gap={4}>
<Box>
<h3>Tag.Text with ellipsis (boolean)</h3>
<h3>Tag.Text with ellipsis (default)</h3>
<Tag w={120} size='m'>
<Tag.Text ellipsis>Long tag text that should be truncated</Tag.Text>
<Tag.Text>Long tag text that should be truncated</Tag.Text>
</Tag>
</Box>

Expand All @@ -22,9 +22,9 @@ const Demo = () => {
</Box>

<Box>
<h3>Tag.Text without ellipsis (default)</h3>
<h3>Tag.Text with manually disabled ellipsis</h3>
<Tag w={120} size='m'>
<Tag.Text>Long tag text that should be truncated</Tag.Text>
<Tag.Text ellipsis={false}>Long tag text that should be truncated</Tag.Text>
</Tag>
</Box>

Expand Down
Loading