Skip to content
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

Migrate remaining components to TypeScript #2065

Merged
merged 7 commits into from
Apr 26, 2023
Merged
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/perfect-beers-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Migrated the Tabs components to TypeScript.
5 changes: 5 additions & 0 deletions .changeset/real-clouds-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Removed the `sharedPropTypes` export. Type the props using TypeScript instead.
5 changes: 5 additions & 0 deletions .changeset/sour-masks-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Migrated the Carousel components to TypeScript. Added the required `playButtonLabel`, `pauseButtonLabel`, `prevButtonLabel`, and `nextButtonLabel` props.
5 changes: 5 additions & 0 deletions .changeset/three-radios-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Migrated the Sidebar component to TypeScript.
5 changes: 5 additions & 0 deletions .changeset/wise-zoos-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Migrated the Calendar components to TypeScript. Some props are now required. The CalendarTagTwoStep's `clearText` and `confirmText` props have been renamed to `clearButtonLabel` and `confirmButtonLabel` respectively.
58 changes: 43 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 0 additions & 94 deletions packages/circuit-ui/components/AspectRatio/AspectRatio.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { describe, expect, it } from 'vitest';

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

import AspectRatio from './AspectRatio';
import { AspectRatio } from './AspectRatio';

describe('AspectRatio', () => {
it('should render with default styles', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import styled from '@emotion/styled';

import AspectRatio from './AspectRatio';
import { AspectRatio, AspectRatioProps } from './AspectRatio';

const Background = styled('div')`
background: lightgrey;
Expand All @@ -26,7 +26,7 @@ export default {
component: AspectRatio,
};

export const Base = (args) => (
export const Base = (args: AspectRatioProps) => (
<div style={{ width: '50vw' }}>
<AspectRatio {...args}>
<Background />
Expand Down
77 changes: 77 additions & 0 deletions packages/circuit-ui/components/AspectRatio/AspectRatio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2019, SumUp Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Children, forwardRef, cloneElement, ReactElement } from 'react';
import styled from '@emotion/styled';
import { ClassNames, css, ClassNamesContent } from '@emotion/react';

export interface AspectRatioProps {
children?: ReactElement;
aspectRatio?: number;
}

const wrapperStyles = ({ aspectRatio }: { aspectRatio: number }) => css`
display: block;
position: relative;
overflow: hidden;
height: 0;
width: 100%;
padding-top: ${Math.round((1 / aspectRatio) * 100)}%;
`;

const Wrapper = styled('div')(wrapperStyles);

const childStyles = (context: ClassNamesContent) => context.css`
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: ${context.theme.zIndex.absolute};
`;

export const AspectRatio = forwardRef<HTMLDivElement, AspectRatioProps>(
({ aspectRatio, children, ...props }, ref) => {
if (!children) {
return null;
}

const child = Children.only(children);

if (!aspectRatio) {
return (
<div ref={ref} {...props}>
{child}
</div>
);
}

return (
<Wrapper ref={ref} aspectRatio={aspectRatio} {...props}>
<ClassNames>
{(context) =>
cloneElement(child, { className: childStyles(context) })
}
</ClassNames>
</Wrapper>
);
},
);

AspectRatio.displayName = 'AspectRatio';
Loading