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

feat(ButtonLink): add default variant #1211

Merged
merged 28 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6dd6d21
first poc
marcoskolodny Aug 23, 2024
2a0118a
code cleanup
marcoskolodny Aug 23, 2024
f674146
force small for links
marcoskolodny Aug 23, 2024
cbd9651
Merge branch 'master' of github.com:Telefonica/mistica-web into WEB-1…
marcoskolodny Aug 23, 2024
6c7973b
fix minWidth and update screenshots
marcoskolodny Aug 23, 2024
a545a86
refactor code and fix spacing bug in loading buttonLink
marcoskolodny Aug 23, 2024
1bfa75d
remove small true as default
marcoskolodny Aug 23, 2024
da8037f
Empty commit
marcoskolodny Aug 23, 2024
0ab8f88
resolve conflicts
marcoskolodny Aug 23, 2024
bd1d85e
Merge branch 'master' of github.com:Telefonica/mistica-web into WEB-1…
marcoskolodny Aug 26, 2024
698337f
Merge branch 'master' of github.com:Telefonica/mistica-web into WEB-1…
marcoskolodny Aug 26, 2024
3dbbc91
Merge branch 'WEB-1999-refactor-buttons-code' of github.com:Telefonic…
marcoskolodny Aug 26, 2024
aa08430
fix button screenshots
marcoskolodny Aug 26, 2024
c112532
fix buttonLink usages and update screenshots
marcoskolodny Aug 26, 2024
7d242c6
resolve conflicts
marcoskolodny Aug 26, 2024
8fad288
update buttonLink desktop text size
marcoskolodny Aug 28, 2024
27bc159
update text size in desktop small buttonLink
marcoskolodny Aug 28, 2024
0c16950
pull master
marcoskolodny Aug 29, 2024
c2c489b
remove unused code
marcoskolodny Aug 29, 2024
aa18db3
fix logic for buttonLayout/buttonGroup detection of small buttonLink
marcoskolodny Sep 2, 2024
de38a49
fix useLayoutEffect hook
marcoskolodny Sep 2, 2024
829d83a
fix typo
marcoskolodny Sep 2, 2024
8449eb7
pull master
marcoskolodny Sep 11, 2024
8164a40
fix logic for ButtonGroup and ButtonLayout
marcoskolodny Sep 11, 2024
fc40919
code cleanup
marcoskolodny Sep 11, 2024
018f408
update ButtonGroup/ButtonLayout logic for link bleed
marcoskolodny Sep 12, 2024
74e130a
fix conflicts
marcoskolodny Sep 12, 2024
8c82f3f
Merge branch 'master' of github.com:Telefonica/mistica-web into WEB-1…
marcoskolodny Sep 12, 2024
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
11 changes: 8 additions & 3 deletions .storybook/welcome-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ export const Welcome = () => {
</Stack>
<nav style={{margin: '0 -8px'}}>
<Inline space={8}>
<ButtonLink href="https://github.com/Telefonica/mistica">
<ButtonLink small href="https://github.com/Telefonica/mistica">
About Mistica
</ButtonLink>
<ButtonLink href="https://github.com/Telefonica/mistica-web#getting-started">
<ButtonLink
small
href="https://github.com/Telefonica/mistica-web#getting-started"
>
Getting started
</ButtonLink>
<ButtonLink href="/playroom">Go to playroom</ButtonLink>
<ButtonLink small href="/playroom">
Go to playroom
</ButtonLink>
</Inline>
</nav>
</Stack>
Expand Down
30 changes: 15 additions & 15 deletions playroom/snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ const cardSnippets: Array<Snippet> = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},
{
Expand All @@ -1010,7 +1010,7 @@ const cardSnippets: Array<Snippet> = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},
{
Expand All @@ -1033,7 +1033,7 @@ const cardSnippets: Array<Snippet> = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},
{
Expand Down Expand Up @@ -1288,7 +1288,7 @@ const cardSnippets: Array<Snippet> = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},
{
Expand All @@ -1308,7 +1308,7 @@ const cardSnippets: Array<Snippet> = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},

Expand All @@ -1332,23 +1332,23 @@ const titlesSnippets: Array<Snippet> = [
},
{
name: 'Title1 (with link)',
code: '<Title1 right={<ButtonLink onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title1>',
code: '<Title1 right={<ButtonLink small onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title1>',
},
{
name: 'Title2',
code: '<Title2>Some title</Title2>',
},
{
name: 'Title2 (with link)',
code: '<Title2 right={<ButtonLink onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title2>',
code: '<Title2 right={<ButtonLink small onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title2>',
},
{
name: 'Title3',
code: '<Title3>Some title</Title3>',
},
{
name: 'Title3 (with link)',
code: '<Title3 right={<ButtonLink onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title3>',
code: '<Title3 right={<ButtonLink small onPress={() => {}} withChevron bleedRight bleedY>Link</ButtonLink>}>Some title</Title3>',
},
].map((snippet) => ({...snippet, group: 'Titles'}));

Expand Down Expand Up @@ -1548,7 +1548,7 @@ const emptyStatesGroup: Array<Snippet> = [
title="Your cart is empty"
description="Check our marketplaces and find something for you"
button={<ButtonPrimary small onPress={() => {}}>Explore marketplace</ButtonPrimary>}
buttonLink={<ButtonLink onPress={() => {}}>More info</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>More info</ButtonLink>}
/>`,
},
].map((snippet) => ({...snippet, group: 'Empty states'}));
Expand Down Expand Up @@ -1744,7 +1744,7 @@ const exampleScreens: Array<Snippet> = [
label="Password"
helperText="Helper text"
/>
<ButtonLink bleedLeft onPress>
<ButtonLink small bleedLeft onPress>
I’m having problems with my password
</ButtonLink>
</Stack>
Expand All @@ -1757,7 +1757,7 @@ const exampleScreens: Array<Snippet> = [
</Text3>
<TextField name="phone" label="Phone number" prefix="+34" />

<ButtonLink bleedLeft onPress>
<ButtonLink small bleedLeft onPress>
I’m having access problems
</ButtonLink>
</Stack>
Expand Down Expand Up @@ -1946,7 +1946,7 @@ const exampleScreens: Array<Snippet> = [
/>
))}
/>
<ButtonLink bleedLeft onPress={() => {}}>
<ButtonLink small bleedLeft onPress={() => {}}>
See all products
</ButtonLink>
</Stack>
Expand Down Expand Up @@ -1989,7 +1989,7 @@ const exampleScreens: Array<Snippet> = [
/>
))}
/>
<ButtonLink bleedLeft onPress={() => {}}>
<ButtonLink small bleedLeft onPress={() => {}}>
View more
</ButtonLink>
</Stack>
Expand Down Expand Up @@ -2498,7 +2498,7 @@ const carouselSnippets = [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>
))}
/>`,
Expand Down Expand Up @@ -3708,7 +3708,7 @@ export default [
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={<ButtonLink small onPress={() => {}}>Link</ButtonLink>}
/>`,
},
...navigationBarSnippets,
Expand Down
48 changes: 42 additions & 6 deletions src/__private_stories__/button-ellipsis-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,67 @@ const handleOnPress = () => window.alert('pressed!');

type Args = {
text: string;
loadingText: string;
small: boolean;
showSpinner: boolean;
};

export const Default: StoryComponent<Args> = ({text}) => {
export const Default: StoryComponent<Args> = ({text, loadingText, small, showSpinner}) => {
const href = 'https://example.com';

return (
<div data-testid="content" style={{width: 160, border: `1px solid ${skinVars.colors.border}`}}>
<Stack space={8}>
<Title1>ButtonPrimary</Title1>
<ButtonPrimary onPress={handleOnPress}>{text}</ButtonPrimary>
<ButtonPrimary
onPress={handleOnPress}
small={small}
loadingText={loadingText}
showSpinner={showSpinner}
>
{text}
</ButtonPrimary>

<Title1>ButtonSecondary</Title1>

<ButtonSecondary onPress={handleOnPress}>{text}</ButtonSecondary>
<ButtonSecondary
onPress={handleOnPress}
small={small}
loadingText={loadingText}
showSpinner={showSpinner}
>
{text}
</ButtonSecondary>

<Title1>ButtonDanger</Title1>

<ButtonDanger onPress={handleOnPress}>{text}</ButtonDanger>
<ButtonDanger
onPress={handleOnPress}
small={small}
loadingText={loadingText}
showSpinner={showSpinner}
>
{text}
</ButtonDanger>

<Title1>ButtonLink</Title1>
<Text2 as="p" regular>
Button (onPress):
</Text2>
<ButtonLink onPress={handleOnPress}>{text}</ButtonLink>
<ButtonLink
onPress={handleOnPress}
small={small}
loadingText={loadingText}
showSpinner={showSpinner}
>
{text}
</ButtonLink>
<Text2 as="p" regular>
Link (href):
</Text2>
<ButtonLink href={href}>{text}</ButtonLink>
<ButtonLink href={href} small={small} loadingText={loadingText} showSpinner={showSpinner}>
{text}
</ButtonLink>
</Stack>
</div>
);
Expand All @@ -45,4 +78,7 @@ export const Default: StoryComponent<Args> = ({text}) => {
Default.storyName = 'Ellipsis in buttons';
Default.args = {
text: 'Ellipsis text example example',
loadingText: 'Loading ellipsis text example',
small: false,
showSpinner: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ const ExampleCarousel = ({
title={`Title ${idx} carousel ${cardsTitlePrefix}`}
description="Some description"
media={<Image src={tennisUrl} aspectRatio="16:9" />}
buttonLink={<ButtonLink href="https://google.com">Link {idx}</ButtonLink>}
buttonLink={
<ButtonLink small href="https://google.com">
Link {idx}
</ButtonLink>
}
/>
))}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const Default: StoryComponent = () => {
description="Some description"
media={<Image src={tennisUrl} aspectRatio="16:9" />}
buttonLink={
<ButtonLink href="https://google.com">Link {idx}</ButtonLink>
<ButtonLink small href="https://google.com">
Link {idx}
</ButtonLink>
}
/>
))}
Expand All @@ -73,7 +75,11 @@ export const Default: StoryComponent = () => {
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={
<ButtonLink small onPress={() => {}}>
Link
</ButtonLink>
}
/>
</ResponsiveLayout>
</ResponsiveLayout>
Expand All @@ -100,7 +106,11 @@ export const Default: StoryComponent = () => {
Action
</ButtonPrimary>
}
buttonLink={<ButtonLink onPress={() => {}}>Link</ButtonLink>}
buttonLink={
<ButtonLink small onPress={() => {}}>
Link
</ButtonLink>
}
/>
))}
/>
Expand Down
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.
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.
11 changes: 11 additions & 0 deletions src/__screenshot_tests__/button-group-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ test.each(DEVICES)('ButtonGroup (%s)', async (device) => {
expect(image).toMatchImageSnapshot();
});

test.each(DEVICES)('ButtonGroup (%s) - small', async (device) => {
const page = await openStoryPage({
id: 'components-buttons-buttongroup--default',
device,
args: {small: true},
});

const image = await page.screenshot({fullPage: true});
expect(image).toMatchImageSnapshot();
});

test.each(DEVICES)('ButtonGroup - Long text (%s)', async (device) => {
const page = await openStoryPage({
id: 'components-buttons-buttongroup--default',
Expand Down
39 changes: 26 additions & 13 deletions src/__screenshot_tests__/button-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {Device} from '../test-utils';

const DEVICES: Array<Device> = ['MOBILE_IOS', 'MOBILE_ANDROID'];
const BUTTONS = ['Primary button', 'Secondary button', 'Danger button', 'Link button', 'Link button danger'];
const SMALL_BUTTONS = ['Primary button', 'Secondary button', 'Danger button'];

const getCases = () => {
const cases = [];
Expand Down Expand Up @@ -54,7 +53,7 @@ test.each(BUTTONS)('Buttons - %s - disabled', async (button) => {
expect(image).toMatchImageSnapshot();
});

test.each(SMALL_BUTTONS)('Buttons - %s - small', async (button) => {
test.each(BUTTONS)('Buttons - %s - small', async (button) => {
await openStoryPage({
id: `components-buttons--${button.toLowerCase().replaceAll(' ', '-')}`,
device: 'MOBILE_IOS',
Expand All @@ -80,17 +79,31 @@ test.each(getCases())('Buttons - %s - spinner (%s)', async (button, device) => {
expect(image).toMatchImageSnapshot();
});

test.each(DEVICES)('Buttons - ellipsis (%s)', async (device) => {
await openStoryPage({
id: 'private-ellipsis-in-buttons--default',
device,
});

const story = await screen.findByTestId('content');

const image = await story.screenshot();
expect(image).toMatchImageSnapshot();
});
test.each`
device | small | showSpinner
${'MOBILE_IOS'} | ${true} | ${true}
${'MOBILE_IOS'} | ${true} | ${false}
${'MOBILE_IOS'} | ${false} | ${true}
${'MOBILE_IOS'} | ${false} | ${false}
${'MOBILE_ANDROID'} | ${true} | ${true}
${'MOBILE_ANDROID'} | ${true} | ${false}
${'MOBILE_ANDROID'} | ${false} | ${true}
${'MOBILE_ANDROID'} | ${false} | ${false}
`(
'Buttons - ellipsis with small = $small and showSpinner = $showSpinner ($device)',
async ({device, small, showSpinner}) => {
await openStoryPage({
id: 'private-ellipsis-in-buttons--default',
device,
args: {small, showSpinner},
});

const story = await screen.findByTestId('content');

const image = await story.screenshot();
expect(image).toMatchImageSnapshot();
}
);

const BUTTON_LINK_ACTIONS = ['href', 'to', 'onPress'];
const BUTTON_LINK_CHEVRON_OPTIONS = ['default', 'true', 'false'];
Expand Down
4 changes: 3 additions & 1 deletion src/__stories__/button-group-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const Default: StoryComponent<Args> = ({
) : undefined;

const linkButton = buttonLink ? (
<ButtonLink onPress={handleOnPress}>{buttonLinkText}</ButtonLink>
<ButtonLink small={small} onPress={handleOnPress}>
{buttonLinkText}
</ButtonLink>
) : undefined;

return <ButtonGroup primaryButton={primaryButton} secondaryButton={secondaryButton} link={linkButton} />;
Expand Down
Loading
Loading