Skip to content

Commit

Permalink
add a TierIndicator component
Browse files Browse the repository at this point in the history
  • Loading branch information
sirineJ committed Feb 27, 2025
1 parent efcaa78 commit efc628a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 62 deletions.
46 changes: 0 additions & 46 deletions packages/circuit-ui/components/TierIndicator/PlusTierIndicator.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { describe, expect, it } from 'vitest';
import { createRef } from 'react';

import { render, axe } from '../../util/test-utils.js';

Expand All @@ -22,13 +23,22 @@ import { TierIndicator } from './TierIndicator.js';
describe('TierIndicator', () => {
it('should merge a custom class name with the default ones', () => {
const className = 'foo';
const { container } = render(<TierIndicator className={className} />);
const { container } = render(
<TierIndicator variant="Plus" className={className} />,
);
const tierIndicator = container.querySelector('h2');
expect(tierIndicator?.className).toContain(className);

Check failure on line 30 in packages/circuit-ui/components/TierIndicator/TierIndicator.spec.tsx

View workflow job for this annotation

GitHub Actions / ci (20)

AssertionError: the given combination of arguments (undefined and string) is invalid for this assertion. You can use an array, a map, an object, a set, a string, or a weakset instead of a string

at packages/circuit-ui/components/TierIndicator/TierIndicator.spec.tsx:30:38

Check failure on line 30 in packages/circuit-ui/components/TierIndicator/TierIndicator.spec.tsx

View workflow job for this annotation

GitHub Actions / ci (22)

AssertionError: the given combination of arguments (undefined and string) is invalid for this assertion. You can use an array, a map, an object, a set, a string, or a weakset instead of a string

at packages/circuit-ui/components/TierIndicator/TierIndicator.spec.tsx:30:38
});

it('should forward a ref', () => {
const ref = createRef<SVGSVGElement>();
const { container } = render(<TierIndicator variant="Plus" />);
const tierIndicator = container.querySelector('h2');
expect(ref.current).toBe(tierIndicator);
});

it('should meet accessibility guidelines', async () => {
const { container } = render(<TierIndicator />);
const { container } = render(<TierIndicator variant="Plus" />);
const actual = await axe(container);
expect(actual).toHaveNoViolations();
});
Expand Down
28 changes: 14 additions & 14 deletions packages/circuit-ui/components/TierIndicator/TierIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
* limitations under the License.
*/

import type { HTMLAttributes } from 'react';
import { forwardRef, type HTMLAttributes } from 'react';
import { PlusTier } from '@sumup-oss/icons';

import { PlusTierIndicator } from './PlusTierIndicator.js';
const SIZES = ['16', '24', '32'] as const;

export interface TierIndicatorProps extends HTMLAttributes<SVGElement> {
/**
* The tier name.
*/
tier: 'Plus';
variant: 'Plus';
/**
* Choose from 3 font sizes. Defaults to `m`.
* Choose from 3 sizes.
* @default `m`.
*/
size?: 's' | 'm' | 'l';
}
const sizeMap: Record<string, { width: string; height: string }> = {
s: { width: '36', height: '16' },
m: { width: '49', height: '24' },
l: { width: '63', height: '28' },
const sizeMap: Record<string, (typeof SIZES)[number]> = {
s: '16',
m: '24',
l: '32',
};

export const TierIndicator = ({ size = 's', ...props }: TierIndicatorProps) => (
<PlusTierIndicator
width={sizeMap[size].width}
height={sizeMap[size].height}
{...props}
/>
export const TierIndicator = forwardRef<SVGSVGElement, TierIndicatorProps>(
({ size = 'm', ...props }, ref) => (
<PlusTier ref={ref} size={sizeMap[size]} {...props} />
),
);

0 comments on commit efc628a

Please sign in to comment.