Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertCarreras committed Oct 1, 2024
1 parent 05183a6 commit c5dc154
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 59 deletions.
53 changes: 34 additions & 19 deletions docs/examples/buttonlink/colors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,40 @@ export default function Example() {
return (
<Box padding={4}>
<Flex gap={6} height="100%" width="100%" wrap>
{['gray', 'red', 'blue', 'transparent'].map((color) => (
<Flex key={color} direction="column" gap={2}>
<Box
alignItems="center"
borderStyle="sm"
display="flex"
height={200}
justifyContent="center"
rounding={4}
width={200}
>
{/* @ts-expect-error - TS2322 - Type 'string' is not assignable to type '"gray" | "red" | "white" | "transparent" | "blue" | "semiTransparentWhite" | "transparentWhiteText" | undefined'. */}
<ButtonLink color={color} href="" iconEnd="visit" size="lg" text="Visit" />
</Box>
<Text size="200" weight="bold">
color=&quot;{color}&quot;
</Text>
</Flex>
))}
{['gray', 'red', 'blue', 'transparent'].map((color) => {

const colorCopy: 'gray' | 'red' | 'blue' | 'transparent' = color as
| 'gray'
| 'red'
| 'blue'
| 'transparent';

return (
<Flex key={color} direction="column" gap={2}>
<Box
alignItems="center"
borderStyle="sm"
display="flex"
height={200}
justifyContent="center"
rounding={4}
width={200}
>
<ButtonLink
color={colorCopy}
href="https://pinterest.com"
iconEnd="visit"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit"
/>
</Box>
<Text size="200" weight="bold">
{/* color=&quot;{color}&quot; */}
</Text>
</Flex>
);
})}
</Flex>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/defaultStateExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function Example() {
accessibilityLabel="Visit Pinterest"
color="red"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit Pinterest"
/>
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/disabledStateExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function Example() {
accessibilityLabel="Go back"
disabled
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Go back"
/>
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/iconEndExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function Example() {
href="https://www.pinterest.com/"
iconEnd="visit"
iconStart="sparkle"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit AI solution"
/>
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/iconTooltipToExplainDo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function Example() {
color="red"
disabled
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit Pinterest"
/>
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/iconTooltipToExplainDont.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function Example() {
color="red"
disabled
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Go back"
/>
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/buttonlink/localizationLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export default function Example() {
<Flex alignItems="center" height="100%" justifyContent="center" width="100%">
<ButtonLink
color="red"
href="https://pinterest.com"
href="https://www.pinterest.com/"
iconEnd="visit"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Besuchen Sie Pinterest"
/>
Expand Down
1 change: 1 addition & 0 deletions docs/examples/buttonlink/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function Example() {
color="red"
href="https://pinterest.com"
iconEnd="visit"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit Pinterest"
/>
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/buttonlink/placePrimaryButtonDo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ export default function Example() {
<ButtonLink
color="red"
fullWidth
href="https://gestalt.pinterest.systems/"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Learn more"
/>
<ButtonLink
color="gray"
fullWidth
href="https://gestalt.pinterest.systems/get_started/developers/installation"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Install now"
/>
Expand Down
16 changes: 14 additions & 2 deletions docs/examples/buttonlink/placePrimaryButtonDont.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ export default function Example() {
return (
<Flex alignItems="center" height="100%" justifyContent="center" width="100%">
<ButtonGroup>
<ButtonLink color="red" href="pinterest.com" size="lg" text="Visit" />
<ButtonLink color="red" href="pinterest.com" size="lg" text="Save" />
<ButtonLink
color="red"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit"
/>
<ButtonLink
color="red"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Save"
/>
</ButtonGroup>
</Flex>
);
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/buttonlink/relAndTargetExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export default function Example() {
<Flex alignItems="center" height="100%" justifyContent="center" width="100%">
<ButtonLink
accessibilityLabel="Visit Pinterest"
href="#"
href="https://www.pinterest.com/"
iconEnd="visit"
onClick={({ event }) => event.preventDefault()}
rel="nofollow"
size="lg"
target="blank"
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/buttonlink/showFullTextDo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export default function Example() {
color="red"
fullWidth
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Create account"
/>
<ButtonLink
color="gray"
fullWidth
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="View settings"
/>
Expand Down
16 changes: 14 additions & 2 deletions docs/examples/buttonlink/showFullTextDont.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ export default function Example() {
justifyContent="center"
width="100%"
>
<ButtonLink color="gray" href="https://www.pinterest.com/" size="lg" text="Kontoeinst..." />
<ButtonLink color="red" href="https://www.pinterest.com/" size="lg" text="Neues We..." />
<ButtonLink
color="gray"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Kontoeinst..."
/>
<ButtonLink
color="red"
href="https://www.pinterest.com/"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Neues We..."
/>
</Flex>
);
}
57 changes: 35 additions & 22 deletions docs/examples/buttonlink/washColors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@ export default function Example() {
return (
<Box padding={4}>
<Flex gap={6} height="100%" width="100%" wrap>
{['semiTransparentWhite', 'transparentWhiteText', 'white'].map((color) => (
<Flex key={color} direction="column" gap={2}>
<Box
alignItems="center"
borderStyle="sm"
dangerouslySetInlineStyle={{
__style: { backgroundImage: 'url("https://i.ibb.co/d0pQsJz/stock3.jpg")' },
}}
display="flex"
height={200}
justifyContent="center"
rounding={4}
width={200}
>
{/* @ts-expect-error - TS2322 - Type 'string' is not assignable to type '"gray" | "red" | "white" | "transparent" | "blue" | "semiTransparentWhite" | "transparentWhiteText" | undefined'. */}
<ButtonLink color={color} href="" iconEnd="visit" size="lg" text="Visit" />
</Box>
<Text size="200" weight="bold">
color=&quot;{color}&quot;
</Text>
</Flex>
))}
{['semiTransparentWhite', 'transparentWhiteText', 'white'].map((color) => {
const colorCopy: 'semiTransparentWhite' | 'transparentWhiteText' | 'white' = color as
| 'semiTransparentWhite'
| 'transparentWhiteText'
| 'white';

return (
<Flex key={color} direction="column" gap={2}>
<Box
alignItems="center"
borderStyle="sm"
dangerouslySetInlineStyle={{
__style: { backgroundImage: 'url("https://i.ibb.co/d0pQsJz/stock3.jpg")' },
}}
display="flex"
height={200}
justifyContent="center"
rounding={4}
width={200}
>
<ButtonLink
color={colorCopy}
href="https://www.pinterest.com/"
iconEnd="visit"
onClick={({ event }) => event.preventDefault()}
size="lg"
text="Visit"
/>
</Box>
<Text size="200" weight="bold">
color=&quot;{color}&quot;
</Text>
</Flex>
);
})}
</Flex>
</Box>
);
Expand Down
46 changes: 37 additions & 9 deletions packages/gestalt/src/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Icon from './Icon';
import icons from './icons/index';
import InternalLink from './Link/InternalLink';
import Text from './Text';
import TextUI from './TextUI';
import useInExperiment from './useInExperiment';

const DEFAULT_TEXT_COLORS = {
blue: 'inverse',
Expand Down Expand Up @@ -49,6 +51,11 @@ type ButtonProps = {
* Indicates if ButtonLink is disabled. Disabled Buttons are inactive and cannot be interacted with.
*/
disabled?: boolean;
/**
* Indicates whether this component is hosted in a light or dark container.
* Used for improving focus ring color contrast.
*/
focusColor?: 'lightBackground' | 'darkBackground';
/**
* An icon displayed after the text to help clarify the usage of ButtonLink. See the [icon variant](#Icons) to learn more.
*/
Expand Down Expand Up @@ -111,6 +118,7 @@ const ButtonLinkWithForwardRef = forwardRef<HTMLAnchorElement, ButtonProps>(func
color = 'gray',
dataTestId,
disabled = false,
focusColor,
fullWidth = false,
iconEnd,
iconStart,
Expand All @@ -124,13 +132,26 @@ const ButtonLinkWithForwardRef = forwardRef<HTMLAnchorElement, ButtonProps>(func
}: ButtonProps,
ref,
) {
const textSizesVR: {
[key: string]: 'xs' | 'sm' | 'md';
} = {
sm: 'xs',
md: 'sm',
lg: 'md',
};

const innerRef = useRef<null | HTMLAnchorElement>(null);

// When using both forwardRef and innerRef, React.useimperativehandle() allows a parent component
// that renders <ButtonLink ref={inputRef} /> to call inputRef.current.focus()
// @ts-expect-error - TS2322 - Type 'HTMLAnchorElement | null' is not assignable to type 'HTMLAnchorElement'.
useImperativeHandle(ref, () => innerRef.current);

const isInVRExperiment = useInExperiment({
webExperimentName: 'web_gestalt_visualRefresh',
mwebExperimentName: 'web_gestalt_visualRefresh',
});

const { accessibilityNewTabLabel } = useDefaultLabelContext('Link');

const { colorSchemeName } = useColorScheme();
Expand Down Expand Up @@ -170,6 +191,7 @@ const ButtonLinkWithForwardRef = forwardRef<HTMLAnchorElement, ButtonProps>(func
colorClass={colorClass}
dataTestId={dataTestId}
disabled={disabled}
focusColor={focusColor}
fullWidth={fullWidth}
href={href}
onClick={handleClick}
Expand All @@ -189,15 +211,21 @@ const ButtonLinkWithForwardRef = forwardRef<HTMLAnchorElement, ButtonProps>(func
size={SIZE_NAME_TO_PIXEL[size]}
/>
) : null}
<Text
align="center"
color={textColor}
overflow="normal"
size={size === 'sm' ? '200' : '300'}
weight="bold"
>
{text}
</Text>
{isInVRExperiment ? (
<TextUI align="center" color={textColor} overflow="normal" size={textSizesVR[size]}>
{text}
</TextUI>
) : (
<Text
align="center"
color={textColor}
overflow="normal"
size={size === 'sm' ? '200' : '300'}
weight="bold"
>
{text}
</Text>
)}
{iconEnd ? (
<Icon
accessibilityLabel=""
Expand Down
Loading

0 comments on commit c5dc154

Please sign in to comment.