New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button, TextLink: Add support for trailing icons #1242
Conversation
🦋 Changeset detectedLatest commit: f31e78f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/braid-design-system/src/lib/components/TextLink/TextLink.docs.tsx
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.docs.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.docs.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/Button/Button.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/Button/Button.docs.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.docs.tsx
Outdated
Show resolved
Hide resolved
packages/braid-design-system/src/lib/components/TextLink/TextLink.docs.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space?: Space; | ||
} | ||
|
||
export const AvoidWidowIcon = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll batch a few suggestions into one and you can pick and choose what you like:
- make the
children
prop more restrictive - rename the
children
prop toicon
inside the render function, to make it clear (to humans) what it is - move the comment above the HTML entity
import type { UseIconProps } from '../../../hooks/useIcon';
import React from 'react';
import type { Space } from '../../../css/atoms/atoms';
import type { BoxProps } from '../../Box/Box';
import { Box } from '../../Box/Box';
import * as styles from './AvoidWidowIcon.css';
interface Props extends Pick<BoxProps, 'className'> {
iconPosition: 'leading' | 'trailing';
space?: Space;
children: React.ReactElement<UseIconProps>;
}
export const AvoidWidowIcon = ({
children: icon,
iconPosition,
space = 'xxsmall',
className,
}: Props) => (
<Box
component="span"
paddingRight={iconPosition === 'leading' ? space : undefined}
paddingLeft={iconPosition === 'trailing' ? space : undefined}
className={[styles.nowrap, className]}
aria-hidden
>
{iconPosition === 'leading' ? icon : undefined}
{/* Word joiner character, a zero-width non-breaking character to prevent the icon wrapping onto its own line */}
⁠
{iconPosition === 'trailing' ? icon : undefined}
</Box>
);
Provide support for choosing the position of the
icon
slot within aButton
orTextLink
.By default, the
iconPosition
will beleading
the label, but optionally, can be set totrailing
.EXAMPLE USAGE: