-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**What does this PR do?** - Create a Link Kit for Rails and React. - Add color, dark, disabled, icon, icon right, tag, and underline props [PLAY-1479](https://runway.powerhrg.com/backlog_items/PLAY-1479) **Screenshots:** Screenshots to visualize your addition/change ![Screenshot 2024-10-25 at 9 52 18 AM](https://github.com/user-attachments/assets/45f0d1af-a340-4558-a9cc-909bbc4a813a) **How to test?** Steps to confirm the desired behavior: 1. Go to /kits/link/ 2. Test Rails and React 3. Compare the handoff to each prop 4. Visit the link (in a non-incognito window). Go back, the link should be purple and "visited" 5. Hover over links to see the color 6. "Focus" on the link by tabbing until you hit the link 7. Use dark mode #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [x] **TESTS** I have added test coverage to my code.
- Loading branch information
Showing
23 changed files
with
667 additions
and
1 deletion.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@import "../tokens/colors"; | ||
@import "../tokens/line_height"; | ||
@import "../tokens/typography"; | ||
@import "../tokens/border_radius"; | ||
|
||
[class^=pb_link_kit]{ | ||
@include pb_link($primary); | ||
&:hover { | ||
color: $text_lt_default; | ||
} | ||
&:focus { | ||
outline: none; | ||
} | ||
&:focus-visible { | ||
border-radius: $border_rad_light; | ||
outline: 1px solid $primary; | ||
outline-offset: 2px; | ||
} | ||
&:visited { | ||
color: $data_3; | ||
} | ||
&.dark { | ||
@include pb_link($active_dark); | ||
&:hover { | ||
color: $text_dk_default; | ||
} | ||
} | ||
@each $color_name, $color_value in $pb_link_colors { | ||
&[class*=_#{"" + $color_name}] { | ||
@include pb_link($color_value); | ||
|
||
&:hover { | ||
color: map-get($pb_link_hover_colors, $color_name); | ||
} | ||
|
||
&:visited { | ||
color: $data_3; | ||
} | ||
} | ||
} | ||
|
||
@each $dark_color_name, $dark_color_value in $pb_dark_link_colors{ | ||
&[class*=_#{$dark_color_name}][class*=dark]{ | ||
@include pb_link($dark_color_value); | ||
|
||
&:hover { | ||
color: map-get($pb_dark_link_hover_colors, $dark_color_name); | ||
} | ||
|
||
&:visited { | ||
color: $data_3; | ||
} | ||
} | ||
} | ||
|
||
&[class*=_underline] { | ||
text-decoration: underline; | ||
} | ||
|
||
&[class*=_disabled] { | ||
pointer-events: none; | ||
cursor: default; | ||
color: $text_lt_lighter; | ||
} | ||
|
||
} |
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,107 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props' | ||
import { globalProps, GlobalProps } from '../utilities/globalProps' | ||
|
||
import Icon from '../pb_icon/_icon' | ||
|
||
type LinkProps = { | ||
aria?: {[key: string]: string}, | ||
className?: string, | ||
children?: React.ReactChild[] | React.ReactChild, | ||
color?: 'default' | 'body' | 'muted' | 'destructive', | ||
dark?: boolean, | ||
data?: {[key: string]: string}, | ||
disabled?: boolean, | ||
href?: string, | ||
htmlOptions?: {[key: string]: string | number | boolean | (() => void) | ((arg?: Event) => void)}, | ||
icon?: string, | ||
iconRight?: string, | ||
id?: string, | ||
tag?: 'a' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span' | 'div', | ||
text?: string, | ||
underline?: boolean, | ||
} & GlobalProps | ||
|
||
const Link = (props: LinkProps): React.ReactElement => { | ||
const { | ||
aria = {}, | ||
children, | ||
className, | ||
color = '', | ||
data = {}, | ||
disabled = false, | ||
href= '', | ||
htmlOptions = {}, | ||
icon = '', | ||
iconRight = '', | ||
id = '', | ||
tag = 'a', | ||
text = '', | ||
underline = false, | ||
} = props | ||
|
||
const ariaProps: {[key: string]: string} = buildAriaProps(aria) | ||
const dataProps: {[key: string]: string} = buildDataProps(data) | ||
const htmlProps = buildHtmlProps(htmlOptions); | ||
const classes = classnames( | ||
buildCss('pb_link_kit', color, underline ? 'underline' : '', disabled ? 'disabled' : ''), | ||
globalProps(props), | ||
className | ||
) | ||
const Tag = tag as keyof JSX.IntrinsicElements | ||
|
||
const renderContent = () => ( | ||
<> | ||
{icon && ( | ||
<Icon | ||
fixedWidth | ||
icon={icon} | ||
marginRight="xxs" | ||
size="xs" | ||
/> | ||
)} | ||
{text || children} | ||
{iconRight && ( | ||
<Icon | ||
fixedWidth | ||
icon={iconRight} | ||
marginLeft="xxs" | ||
size="xs" | ||
/> | ||
)} | ||
</> | ||
) | ||
|
||
const commonProps = { | ||
...ariaProps, | ||
...dataProps, | ||
...htmlProps, | ||
className: classes, | ||
id, | ||
} | ||
|
||
if (tag === 'a') { | ||
return ( | ||
<a | ||
{...commonProps} | ||
href={href} | ||
> | ||
{renderContent()} | ||
</a> | ||
) | ||
} else { | ||
return ( | ||
<a | ||
{...commonProps} | ||
href={href} | ||
> | ||
<Tag>{renderContent()}</Tag> | ||
</a> | ||
) | ||
} | ||
|
||
} | ||
|
||
export default Link |
30 changes: 30 additions & 0 deletions
30
playbook/app/pb_kits/playbook/pb_link/docs/_link_color.html.erb
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,30 @@ | ||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "https://www.google.com/search?q=playbook+design+system", | ||
}) %> | ||
</div> | ||
|
||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "https://www.youtube.com/@PowerHRG", | ||
color: "body", | ||
}) %> | ||
</div> | ||
|
||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "https://github.com/powerhome/.github/blob/main/profile/README.md", | ||
color: "muted", | ||
}) %> | ||
</div> | ||
|
||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "https://rubygems.org/gems/playbook_ui/", | ||
color: "destructive", | ||
}) %> | ||
</div> |
40 changes: 40 additions & 0 deletions
40
playbook/app/pb_kits/playbook/pb_link/docs/_link_color.jsx
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,40 @@ | ||
import React from 'react' | ||
import { Link } from 'playbook-ui' | ||
|
||
const LinkColor = (props) => ( | ||
<div> | ||
<div> | ||
<Link | ||
href="https://www.google.com/search?q=playbook+design+system" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
<div> | ||
<Link | ||
color="body" | ||
href="https://www.youtube.com/@PowerHRG" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
<div> | ||
<Link | ||
color="muted" | ||
href="https://github.com/powerhome/.github/blob/main/profile/README.md" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
<div> | ||
<Link | ||
color="destructive" | ||
href="https://rubygems.org/gems/playbook_ui/" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
|
||
export default LinkColor |
5 changes: 5 additions & 0 deletions
5
playbook/app/pb_kits/playbook/pb_link/docs/_link_disabled.html.erb
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,5 @@ | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "#disabled", | ||
disabled: true, | ||
}) %> |
15 changes: 15 additions & 0 deletions
15
playbook/app/pb_kits/playbook/pb_link/docs/_link_disabled.jsx
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,15 @@ | ||
import React from 'react' | ||
import { Link } from 'playbook-ui' | ||
|
||
const LinkDisabled = (props) => ( | ||
<div> | ||
<Link | ||
disabled | ||
href="#disabled" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
) | ||
|
||
export default LinkDisabled |
15 changes: 15 additions & 0 deletions
15
playbook/app/pb_kits/playbook/pb_link/docs/_link_icon.html.erb
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,15 @@ | ||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "#icon", | ||
icon: "arrow-up-right-from-square", | ||
}) %> | ||
</div> | ||
|
||
<div> | ||
<%= pb_rails("link", props: { | ||
text: "link example", | ||
href: "#icon2", | ||
icon_right: "chevron-right", | ||
}) %> | ||
</div> |
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,25 @@ | ||
import React from 'react' | ||
import { Link } from 'playbook-ui' | ||
|
||
const LinkIcon = (props) => ( | ||
<div> | ||
<div> | ||
<Link | ||
href="#icon" | ||
icon="arrow-up-right-from-square" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
<div> | ||
<Link | ||
href="#icon2" | ||
iconRight="chevron-right" | ||
text="link example" | ||
{...props} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
|
||
export default LinkIcon |
Oops, something went wrong.