Skip to content

Commit

Permalink
feat: add Badge & Tabs truncate props
Browse files Browse the repository at this point in the history
  • Loading branch information
vadim-kudr committed Nov 8, 2024
1 parent a1e987f commit e2c16c4
Show file tree
Hide file tree
Showing 57 changed files with 829 additions and 260 deletions.
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.
3 changes: 3 additions & 0 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ true: PolymorphicClassName;
text?: string | undefined;
contentLeft?: ReactNode;
contentRight?: ReactNode;
maxWidth?: Property.Width<string | number> | undefined;
size?: string | undefined;
view?: string | undefined;
} & {
Expand All @@ -750,6 +751,7 @@ transparent?: false | undefined;
text?: string | undefined;
contentLeft?: ReactNode;
contentRight?: ReactNode;
maxWidth?: Property.Width<string | number> | undefined;
size?: string | undefined;
view?: string | undefined;
} & {
Expand All @@ -762,6 +764,7 @@ clear?: false | undefined;
text?: string | undefined;
contentLeft?: ReactNode;
contentRight?: ReactNode;
maxWidth?: Property.Width<string | number> | undefined;
size?: string | undefined;
view?: string | undefined;
} & {
Expand Down
47 changes: 47 additions & 0 deletions packages/plasma-b2c/src/components/Tabs/Tabs.component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,51 @@ describe('plasma-b2c: Tabs', () => {
cy.get('button').contains('Sber').should('be.visible');
cy.get('button').contains('Joy').should('not.be.visible');
});

it('truncate', () => {
mount(
<CypressTestDecorator>
<Tabs size="l" view="divider" forwardedAs="ul">
{items.map((item, i) => (
<TabItem
size="l"
view="divider"
key={i}
selected={i === 1}
forwardedAs="li"
maxItemWidth="2rem"
>
{item.label}
</TabItem>
))}
</Tabs>
<PadMe />
<Tabs size="l" view="divider" forwardedAs="ul" orientation="vertical">
{items.map((item, i) => (
<TabItem
size="l"
view="divider"
orientation="vertical"
key={i}
selected={i === 1}
forwardedAs="li"
maxItemWidth="5rem"
>
{item.label}
</TabItem>
))}
</Tabs>
<PadMe />
<Tabs size="h5" view="clear" forwardedAs="ul">
{items.map((item, i) => (
<TabItem size="h5" view="clear" key={i} selected={i === 1} forwardedAs="li" maxItemWidth="2rem">
{item.label}
</TabItem>
))}
</Tabs>
</CypressTestDecorator>,
);

cy.matchImageSnapshot();
});
});
83 changes: 61 additions & 22 deletions packages/plasma-b2c/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type CustomStoryTabsProps = {

const contentLeftOptions = ['none', 'icon'];
const contentRightOptions = ['none', 'counter', 'icon'];
const labels = ['Label', 'Middle label', 'Very long label'];

const getContentLeft = (contentLeftOption: string, size: Size) => {
const iconSize = size === 'xs' ? 'xs' : 's';
Expand Down Expand Up @@ -81,6 +82,19 @@ const meta: Meta<StoryTabsProps> = {
'outsideScroll',
'index',
]),
contentRight: {
options: contentRightOptions,
control: {
type: 'select',
},
if: { arg: 'helperText', eq: '' },
},
maxItemWidth: {
control: {
type: 'text',
},
if: { arg: 'stretch', truthy: false },
},
},
};

Expand All @@ -95,13 +109,14 @@ const StoryHorizontalDefault = (props: HorizontalStoryTabsProps) => {
contentRight: contentRightOption,
hasDivider,
stretch,
maxItemWidth,
helperText,
} = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);

return (
<Tabs view="divider" hasDivider={hasDivider} stretch={stretch} disabled={disabled} size={size}>
<Tabs clip="none" view="divider" hasDivider={hasDivider} stretch={stretch} disabled={disabled} size={size}>
{items.map((_, i) => {
if (helperText !== '') {
return (
Expand All @@ -115,8 +130,9 @@ const StoryHorizontalDefault = (props: HorizontalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -132,8 +148,9 @@ const StoryHorizontalDefault = (props: HorizontalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -152,6 +169,7 @@ const StoryHorizontalScroll = (props: HorizontalStoryTabsProps) => {
hasDivider,
helperText,
width,
maxItemWidth,
} = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);
Expand All @@ -171,8 +189,9 @@ const StoryHorizontalScroll = (props: HorizontalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -188,8 +207,9 @@ const StoryHorizontalScroll = (props: HorizontalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -207,6 +227,7 @@ const StoryHorizontalShowAll = (props: HorizontalStoryTabsProps) => {
contentRight: contentRightOption,
hasDivider,
helperText,
maxItemWidth,
} = props;
const maxItemQuantity = 3;
const items = Array(itemQuantity).fill(0);
Expand Down Expand Up @@ -239,8 +260,9 @@ const StoryHorizontalShowAll = (props: HorizontalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -256,8 +278,9 @@ const StoryHorizontalShowAll = (props: HorizontalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -274,6 +297,7 @@ const StoryHorizontalShowAll = (props: HorizontalStoryTabsProps) => {
tabIndex={!disabled ? 0 : -1}
disabled={disabled}
size={size as Size}
maxItemWidth="auto"
>
ShowAll
</TabItem>
Expand All @@ -290,9 +314,10 @@ export const HorizontalTabs: StoryObj<HorizontalStoryTabsProps> = {
disabled: false,
hasDivider: true,
helperText: '',
itemQuantity: 8,
itemQuantity: 6,
stretch: false,
width: '15rem',
maxItemWidth: '',
},
argTypes: {
contentLeft: {
Expand Down Expand Up @@ -348,6 +373,7 @@ const StoryVerticalDefault = (props: VerticalStoryTabsProps) => {
contentRight: contentRightOption,
hasDivider,
helperText,
maxItemWidth,
} = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);
Expand All @@ -368,8 +394,9 @@ const StoryVerticalDefault = (props: VerticalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -386,8 +413,9 @@ const StoryVerticalDefault = (props: VerticalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -406,6 +434,7 @@ const StoryVerticalScroll = (props: VerticalStoryTabsProps) => {
hasDivider,
helperText,
height,
maxItemWidth,
} = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);
Expand Down Expand Up @@ -433,8 +462,9 @@ const StoryVerticalScroll = (props: VerticalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -451,8 +481,9 @@ const StoryVerticalScroll = (props: VerticalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -470,6 +501,7 @@ const StoryVerticalShowAll = (props: VerticalStoryTabsProps) => {
contentRight: contentRightOption,
hasDivider,
helperText,
maxItemWidth,
} = props;
const maxItemQuantity = 3;
const items = Array(itemQuantity).fill(0);
Expand Down Expand Up @@ -503,8 +535,9 @@ const StoryVerticalShowAll = (props: VerticalStoryTabsProps) => {
value={helperText}
contentLeft={getContentLeft(contentLeftOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
}
Expand All @@ -521,8 +554,9 @@ const StoryVerticalShowAll = (props: VerticalStoryTabsProps) => {
contentLeft={getContentLeft(contentLeftOption, size as Size)}
contentRight={getContentRight(contentRightOption, size as Size)}
size={size as Size}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
);
})}
Expand All @@ -539,6 +573,7 @@ const StoryVerticalShowAll = (props: VerticalStoryTabsProps) => {
tabIndex={!disabled ? 0 : -1}
disabled={disabled}
size={size as Size}
maxItemWidth="auto"
>
ShowAll
</TabItem>
Expand All @@ -553,10 +588,11 @@ export const VerticalTabs: StoryObj<VerticalStoryTabsProps> = {
size: 'xs',
disabled: false,
hasDivider: true,
itemQuantity: 8,
itemQuantity: 6,
orientation: 'vertical',
helperText: '',
height: '10rem',
maxItemWidth: '',
},
argTypes: {
contentLeft: {
Expand Down Expand Up @@ -609,12 +645,12 @@ export const VerticalTabs: StoryObj<VerticalStoryTabsProps> = {
};

const StoryHeaderDefault = (props: HorizontalStoryTabsProps) => {
const { disabled, itemQuantity, size, helperText } = props;
const { disabled, itemQuantity, size, helperText, maxItemWidth } = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);

return (
<Tabs view="clear" disabled={disabled} size={size}>
<Tabs view="clear" disabled={disabled} size={size as HeaderSize}>
{items.map((_, i) => (
<TabItem
key={`item:${i}`}
Expand All @@ -624,17 +660,18 @@ const StoryHeaderDefault = (props: HorizontalStoryTabsProps) => {
tabIndex={!disabled ? 0 : -1}
disabled={disabled}
value={helperText}
size={size}
size={size as HeaderSize}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
))}
</Tabs>
);
};

const StoryHeaderScroll = (props: HorizontalStoryTabsProps) => {
const { disabled, itemQuantity, size, helperText, width } = props;
const { disabled, itemQuantity, size, helperText, width, maxItemWidth } = props;
const items = Array(itemQuantity).fill(0);
const [index, setIndex] = useState(0);

Expand All @@ -650,8 +687,9 @@ const StoryHeaderScroll = (props: HorizontalStoryTabsProps) => {
disabled={disabled}
value={helperText}
size={size as HeaderSize}
maxItemWidth={maxItemWidth}
>
{`Label${i + 1}`}
{`${labels[i % labels.length]} ${i + 1}`}
</TabItem>
))}
</Tabs>
Expand All @@ -663,8 +701,9 @@ export const HeaderTabs: StoryObj<HorizontalStoryTabsProps> = {
size: 'h5',
disabled: false,
helperText: '',
itemQuantity: 6,
itemQuantity: 4,
width: '12rem',
maxItemWidth: '',
},
argTypes: {
clip: {
Expand Down
Loading

0 comments on commit e2c16c4

Please sign in to comment.