Skip to content

Commit

Permalink
Merge pull request #1018 from glints-dev/feature/link-conditional-center
Browse files Browse the repository at this point in the history
Link: conditionally center if external true
  • Loading branch information
ninariccimarie authored Apr 19, 2024
2 parents f7eb62d + ba7993d commit 5d77674
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/@next/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ export const Default = DefaultTemplate.bind({});
Default.args = {
url: '#',
};

const WithinParagraphTemplate: Story<LinkProps> = args => {
return (
<>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<Link external {...args}>
{' '}
Default Link
</Link>{' '}
Sed volutpat eget mi in consequat. Aliquam cursus nunc pulvinar rutrum
pharetra.
</>
);
};

export const WithinParagraph = WithinParagraphTemplate.bind({});
1 change: 1 addition & 0 deletions src/@next/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Link = ({
data-underline={!removeUnderline}
data-monochrome={monochrome}
{...(external && { target: '_blank' })}
external={external}
{...props}
>
<Typography variant="body1" as="span">
Expand Down
11 changes: 9 additions & 2 deletions src/@next/Link/LinkStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import { Blue, Neutral } from '../utilities/colors';
import { space2 } from '../utilities/spacing';
import { LinkProps } from './Link';

const centerAlign = `
vertical-align: middle;
svg {
vertical-align: middle;
}
`;

export const StyledLink = styled.a<LinkProps>`
display: flex;
align-items: center;
${({ external }) => external && centerAlign}
color: ${Blue.S99};
&[data-underline='false'] {
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/link/link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ test('Link - monochrome with external link', async ({ page }) => {
'link-monochrome-with-external-pressed.png'
);
});

test('Link - within paragraph', async ({ page }) => {
const linkPage = new LinkPage(page);
await linkPage.gotoWithinParagraphPage();
await expect(linkPage.container).toHaveScreenshot(
'link-within-paragraph.png'
);
});
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.
7 changes: 6 additions & 1 deletion test/e2e/link/linkPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Locator, Page } from '@playwright/test';
import { StoryBookPage } from '../storybookPage';
import { Args, StoryBookPage } from '../storybookPage';

export class LinkPage extends StoryBookPage {
readonly link: Locator;
Expand All @@ -10,4 +10,9 @@ export class LinkPage extends StoryBookPage {
.frameLocator('internal:attr=[title="storybook-preview-iframe"i]')
.getByText('Default Link');
}

async gotoWithinParagraphPage(args?: Args) {
this.setPath('?path=/story/next-link--within-paragraph');
await this.goto(args);
}
}

0 comments on commit 5d77674

Please sign in to comment.