Skip to content

fix: Fix i8n errors by adding spans to button children #1703

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-steaks-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@launchpad-ui/components": minor
---

Add spans to button children to fix i8n errors
13 changes: 4 additions & 9 deletions packages/components/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import type { ButtonProps as AriaButtonProps, ContextValue } from 'react-aria-co

import { cva } from 'class-variance-authority';
import { createContext, useContext } from 'react';
import {
Button as AriaButton,
composeRenderProps,
Provider,
TextContext,
} from 'react-aria-components';
import { Button as AriaButton, composeRenderProps } from 'react-aria-components';

import { PerceivableContext } from './Perceivable';
import { ProgressBar } from './ProgressBar';
Expand Down Expand Up @@ -67,12 +62,12 @@ const Button = ({ ref, ...props }: ButtonProps) => {
)}
>
{composeRenderProps(props.children, (children, { isPending }) => (
<Provider values={[[TextContext, { className: isPending ? styles.pending : undefined }]]}>
<>
{isPending && (
<ProgressBar isIndeterminate aria-label="loading" className={styles.progress} />
)}
{children}
</Provider>
<span className={styles.content}>{children}</span>
</>
))}
</AriaButton>
);
Expand Down
27 changes: 18 additions & 9 deletions packages/components/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PopoverContext,
Provider,
Text,
TextContext,
useSlottedContext,
} from 'react-aria-components';

Expand Down Expand Up @@ -181,22 +182,30 @@ const DatePickerValue = () => {
const { locale } = useLocale();
const date = state?.formatValue(locale, { month: 'short' });

return <Text className={styles.value}>{date}</Text>;
return (
<TextContext.Provider value={undefined}>
<Text className={styles.value}>{date}</Text>
</TextContext.Provider>
);
};

const DateRangePickerValue = () => {
const state = useContext(DateRangePickerStateContext);
const { locale } = useLocale();
const date = state?.formatValue(locale, { month: 'short' });

return date?.start === date?.end ? (
<Text className={styles.value}>{date?.end}</Text>
) : (
<>
<Text>{date?.start}</Text>
<Icon name="arrow-right-thin" size="small" />
<Text className={styles.value}>{date?.end}</Text>
</>
return (
<TextContext.Provider value={undefined}>
{date?.start === date?.end ? (
<Text className={styles.value}>{date?.end}</Text>
) : (
<>
<Text>{date?.start}</Text>
<Icon name="arrow-right-thin" size="small" />
<Text className={styles.value}>{date?.end}</Text>
</>
)}
</TextContext.Provider>
);
};

Expand Down
20 changes: 15 additions & 5 deletions packages/components/src/styles/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
opacity: 0.64;
}

.content {
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--lp-spacing-200);
min-width: 0;
}

.small {
font: var(--lp-text-label-2-semibold);
padding: calc(3px + var(--lp-button-padding, 0px)) var(--lp-spacing-300);
Expand Down Expand Up @@ -142,15 +150,12 @@
.button[data-pending] {
cursor: wait;

& [data-icon] {
& [data-icon],
.content {
opacity: 50%;
}
}

.pending {
opacity: 50%;
}

.progress {
--fill-color: currentColor;
}
Expand All @@ -164,4 +169,9 @@
& [data-icon]:last-child {
fill: var(--lp-color-fill-ui-secondary);
}

& .content {
flex: 1;
gap: var(--lp-spacing-300);
}
}
2 changes: 1 addition & 1 deletion packages/components/src/styles/Group.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
fill: var(--lp-color-fill-ui-secondary);
}

&[data-disabled] > :where([data-icon]) {
&[data-disabled] :where([data-icon]) {
opacity: 0.64;
}
}
18 changes: 8 additions & 10 deletions packages/components/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useEffect, useRef, useState } from 'react';
import { fireEvent, userEvent, within } from 'storybook/test';

import { Button } from '../src/Button';
import { Text } from '../src/Text';

const meta: Meta<typeof Button> = {
component: Button,
Expand Down Expand Up @@ -75,23 +74,22 @@ const play: PlayFunction<ReactRenderer> = async ({
};

export const Default: Story = {
render: (args) => renderStates({ children: <Text>Default</Text>, ...args }),
render: (args) => renderStates({ children: 'Default', ...args }),
play,
};

export const Primary: Story = {
render: (args) => renderStates({ children: <Text>Primary</Text>, variant: 'primary', ...args }),
render: (args) => renderStates({ children: 'Primary', variant: 'primary', ...args }),
play,
};

export const Minimal: Story = {
render: (args) => renderStates({ children: <Text>Minimal</Text>, variant: 'minimal', ...args }),
render: (args) => renderStates({ children: 'Minimal', variant: 'minimal', ...args }),
play,
};

export const Destructive: Story = {
render: (args) =>
renderStates({ children: <Text>Destructive</Text>, variant: 'destructive', ...args }),
render: (args) => renderStates({ children: 'Destructive', variant: 'destructive', ...args }),
play,
parameters: {
a11y: {
Expand All @@ -108,20 +106,20 @@ export const WithIcon: Story = {
args: {
children: (
<>
<Text>With icon </Text>
With icon
<Icon name="add" size="small" />
</>
),
},
};

export const Small: Story = {
render: (args) => renderStates({ children: <Text>Default</Text>, size: 'small', ...args }),
render: (args) => renderStates({ children: 'Default', size: 'small', ...args }),
play,
};

export const Large: Story = {
render: (args) => renderStates({ children: <Text>Default</Text>, size: 'large', ...args }),
render: (args) => renderStates({ children: 'Default', size: 'large', ...args }),
play,
};

Expand All @@ -147,7 +145,7 @@ export const Pending: Story = {
return <Button isPending={isPending} onPress={handlePress} {...args} />;
},
args: {
children: <Text>Pending</Text>,
children: 'Pending',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
Expand Down
Loading