-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removing useless doc snippet * adding KnowMore component * adding KnowMore test * adding KnowMore stories * component renaming * adding button variation * linting * helpLink breadcrumb integration * linting * tests fix
- Loading branch information
Showing
5 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from "react" | ||
import { composeStories } from "@storybook/testing-react" | ||
import { mount } from "@cypress/react" | ||
import * as stories from "./HelpLink.stories" | ||
|
||
const { Default, Button, NoTextOnMobile } = composeStories(stories) | ||
|
||
const specTitle = require('cypress-sonarqube-reporter/specTitle'); | ||
describe(specTitle('HelpLink tests'), () => { | ||
|
||
it('Default', () => { | ||
mount(<Default />) | ||
cy.get('#helpLinkContainer').within(() => { | ||
cy.get('span').should('have.class', 'text-f6').and('have.class', 'font-semibold').contains('Saiba mais') | ||
}) | ||
}) | ||
|
||
it('Button', () => { | ||
mount(<Button />) | ||
cy.get('#helpLinkContainer').within(() => { | ||
cy.get('span').should('have.class', 'text-f6').and('have.class', 'font-semibold').contains('Saiba mais') | ||
cy.get('#helpLinkContainer').should(() => {alert(`Clicked!`)}) | ||
}) | ||
}) | ||
|
||
it('NoTextOnMobile', () => { | ||
mount(<NoTextOnMobile />) | ||
cy.get('#helpLinkContainer').within(() => { | ||
cy.get('span').should('have.class', 'hidden').and('have.class', 'md:inline').contains('Saiba mais') | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react' | ||
import { Story, Meta } from '@storybook/react' | ||
|
||
import { HelpLink, HelpLinkProps } from '.' | ||
|
||
export default { | ||
title: 'Navigation/HelpLink', | ||
component: HelpLink, | ||
parameters: { | ||
layout: 'padded', | ||
} | ||
} as Meta | ||
|
||
const Template: Story<HelpLinkProps> = args => <HelpLink {...args} /> | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
text: 'Saiba mais', | ||
as: 'hyperLink', | ||
href: 'https://www.lojaintegrada.com.br' | ||
} | ||
|
||
export const Button = Template.bind({}) | ||
Button.args = { | ||
text: 'Saiba mais', | ||
as: 'button', | ||
onClick: function() { | ||
alert('Clicked!') | ||
} | ||
} | ||
|
||
export const NoTextOnMobile = Template.bind({}) | ||
NoTextOnMobile.args = { | ||
text: 'Saiba mais', | ||
as: 'hyperLink', | ||
href: 'https://www.lojaintegrada.com.br', | ||
mobileText: false, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react' | ||
import { Icon } from '../../Icons' | ||
|
||
const defaultClass = | ||
'flex p-1 pr-0 text-on-base-2 hover:text-on-base duration-200 transition-colors items-center' | ||
|
||
export const HelpLink: React.FC<HelpLinkProps> = React.memo( | ||
({ | ||
className = '', | ||
text = '', | ||
mobileText, | ||
href = '', | ||
as = 'hyperLink', | ||
onClick, | ||
}) => { | ||
const Text = () => ( | ||
<> | ||
<Icon icon="questionCircle" size={4} className="shrink-0" block /> | ||
<span | ||
className={`text-f6 font-semibold tracking-4 leading-6 ml-2 | ||
${!mobileText ? 'hidden md:inline' : ''} | ||
`} | ||
> | ||
{text} | ||
</span> | ||
</> | ||
) | ||
|
||
const HyperLink = () => ( | ||
<a | ||
className={`${defaultClass} ${className}`} | ||
href={href} | ||
rel="noreferrer" | ||
target="_blank" | ||
id="helpLinkContainer" | ||
> | ||
<Text /> | ||
</a> | ||
) | ||
|
||
const Button = () => ( | ||
<button | ||
className={`${defaultClass} ${className}`} | ||
id="helpLinkContainer" | ||
onClick={onClick} | ||
> | ||
<Text /> | ||
</button> | ||
) | ||
|
||
return as == 'hyperLink' ? <HyperLink /> : <Button /> | ||
} | ||
) | ||
|
||
export interface HelpLinkProps { | ||
/** | ||
* Custom class name | ||
* */ | ||
className?: string | ||
/** | ||
* Text to be displayed | ||
* */ | ||
text?: string | ||
/** | ||
* Text will appear on mobile or not | ||
* */ | ||
mobileText?: boolean | ||
/** | ||
* Component behaviour as hyper link or button | ||
* */ | ||
as: 'hyperLink' | 'button' | ||
/** | ||
* Href to the link where component redirects | ||
* */ | ||
href?: string | ||
/** | ||
* Button action when clicked | ||
* */ | ||
onClick?: React.MouseEventHandler<HTMLButtonElement> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters