Skip to content

Commit

Permalink
fix: correct border radius based on roundness (#4260)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Jan 10, 2024
1 parent aa270b6 commit a62d6ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const Chip = ({
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const { isV3 } = theme;
const { isV3, roundness } = theme;

const { current: elevation } = React.useRef<Animated.Value>(
new Animated.Value(isV3 && elevated ? 1 : 0)
Expand Down Expand Up @@ -237,7 +237,7 @@ const Chip = ({
});

const opacity = isV3 ? 0.38 : 0.26;
const defaultBorderRadius = isV3 ? 8 : 16;
const defaultBorderRadius = roundness * (isV3 ? 2 : 4);
const iconSize = isV3 ? 18 : 16;

const {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FAB/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const v3LargeSize = {
const getCustomFabSize = (customSize: number, roundness: number) => ({
height: customSize,
width: customSize,
borderRadius: customSize / roundness,
borderRadius: roundness === 0 ? 0 : customSize / roundness,
});

export const getFabStyle = ({
Expand Down
12 changes: 12 additions & 0 deletions src/components/__tests__/Chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ it('renders active chip if only onLongPress handler is passed', () => {
});
});

it('renders chip with zero border radius', () => {
const { getByTestId } = render(
<Chip testID="active-chip" theme={{ roundness: 0 }}>
Active chip
</Chip>
);

expect(getByTestId('active-chip')).toHaveStyle({
borderRadius: 0,
});
});

describe('getChipColors - text color', () => {
it('should return correct disabled color, for theme version 3', () => {
expect(
Expand Down
8 changes: 8 additions & 0 deletions src/components/__tests__/FAB.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ it('renders FAB with custom border radius', () => {
expect(getByTestId('fab-container')).toHaveStyle({ borderRadius: 0 });
});

it('renders FAB with zero border radius', () => {
const { getByTestId } = render(
<FAB theme={{ roundness: 0 }} onPress={() => {}} icon="plus" testID="fab" />
);

expect(getByTestId('fab-container')).toHaveStyle({ borderRadius: 0 });
});

it('renders FAB without uppercase styling by default', () => {
const { getByTestId } = render(
<FAB onPress={() => {}} label="Add items" testID="fab" />
Expand Down

0 comments on commit a62d6ec

Please sign in to comment.