-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from LifeSG/inline-popover
Accessibility improvements to PopoverTrigger and new inline popover
- Loading branch information
Showing
12 changed files
with
535 additions
and
167 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./popover-trigger"; | ||
export * from "./popover"; | ||
export * from "./popover-inline"; | ||
export * from "./popover-trigger"; | ||
export * from "./types"; |
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 @@ | ||
export * from "./popover-inline"; |
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,52 @@ | ||
import { Color } from "../../color"; | ||
import styled from "styled-components"; | ||
import { PopoverInlineStyle } from "../types"; | ||
|
||
// ============================================================================= | ||
// STYLE INTERFACE | ||
// ============================================================================= | ||
|
||
interface StyledTextProps { | ||
$defaultStyle: PopoverInlineStyle; | ||
$hoverStyle: PopoverInlineStyle; | ||
} | ||
|
||
interface StyledIconProps { | ||
$standalone: boolean; | ||
} | ||
|
||
// ============================================================================= | ||
// STYLING | ||
// ============================================================================= | ||
const getTextStyle = (style: PopoverInlineStyle) => { | ||
switch (style) { | ||
case "underline": | ||
return "text-decoration: underline 1px;"; | ||
case "underline-dashed": | ||
return "text-decoration: underline dashed 1px;"; | ||
} | ||
}; | ||
|
||
export const StyledText = styled.span<StyledTextProps>` | ||
color: ${Color.Primary}; | ||
font-weight: 600; | ||
text-underline-position: under; | ||
${({ $defaultStyle }) => getTextStyle($defaultStyle)} | ||
&:hover, | ||
&:focus-visible { | ||
color: ${Color.Secondary}; | ||
${({ $hoverStyle }) => getTextStyle($hoverStyle)} | ||
} | ||
svg { | ||
height: 1lh; // align vertically | ||
width: 1em; // scale icon with font size | ||
vertical-align: top; | ||
} | ||
`; | ||
|
||
export const StyledIcon = styled.span<StyledIconProps>` | ||
${(props) => !props.$standalone && "margin-left: 0.25rem;"} | ||
`; |
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,29 @@ | ||
import { PopoverTrigger } from "../popover-trigger"; | ||
import { PopoverInlineProps } from "../types"; | ||
import { StyledIcon, StyledText } from "./popover-inline.styles"; | ||
|
||
export const PopoverInline = ({ | ||
content, | ||
icon, | ||
underlineStyle = "default", | ||
underlineHoverStyle = "default", | ||
...otherProps | ||
}: PopoverInlineProps) => { | ||
// ========================================================================= | ||
// RENDER FUNCTIONS | ||
// ========================================================================= | ||
return ( | ||
<PopoverTrigger {...otherProps}> | ||
<StyledText | ||
role="button" | ||
aria-haspopup="dialog" | ||
tabIndex={0} | ||
$defaultStyle={underlineStyle} | ||
$hoverStyle={underlineHoverStyle} | ||
> | ||
{content} | ||
{icon && <StyledIcon $standalone={!content}>{icon}</StyledIcon>} | ||
</StyledText> | ||
</PopoverTrigger> | ||
); | ||
}; |
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,30 @@ | ||
import { Canvas, Meta } from "@storybook/blocks"; | ||
import { Heading3, Heading4, Secondary, Title } from "../../storybook-common"; | ||
import * as PopoverInlineStories from "./popover-inline.stories"; | ||
import { PropsTable } from "./props-table"; | ||
|
||
<Meta of={PopoverInlineStories} /> | ||
|
||
<Title>PopoverInline</Title> | ||
|
||
<Secondary>Overview</Secondary> | ||
|
||
Provides additional information for content within a text block. | ||
|
||
<Canvas of={PopoverInlineStories.InlineTextAndIcon} /> | ||
|
||
<Heading3>Text style</Heading3> | ||
|
||
The text and icon inherit the font size of the surrounding text. | ||
|
||
<Canvas of={PopoverInlineStories.InlineText} /> | ||
|
||
<Canvas of={PopoverInlineStories.InlineIcon} /> | ||
|
||
<Heading3>Underline style</Heading3> | ||
|
||
<Canvas of={PopoverInlineStories.UnderlineStyle} /> | ||
|
||
<Secondary>Component API</Secondary> | ||
|
||
<PropsTable /> |
Oops, something went wrong.