Skip to content

Commit

Permalink
Migrate remaining components to TypeScript (#2065)
Browse files Browse the repository at this point in the history
* Migrate AspectRatio to TypeScript

* Migrate Calendar components to TypeScript

* Migrate Tabs to TypeScript

* Migrate Carousel to TypeScript

* Migrate Sidebar to TypeScript

* Remove shared prop types

* Add changesets
  • Loading branch information
connor-baer authored Apr 26, 2023
1 parent fef5b95 commit 8adb8fe
Show file tree
Hide file tree
Showing 100 changed files with 1,256 additions and 1,074 deletions.
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

0 comments on commit 8adb8fe

Please sign in to comment.