From 56fece293c4a1c9f0a77903b9820d3b74ff10b3b Mon Sep 17 00:00:00 2001 From: Treycos <19551067+Treycos@users.noreply.github.com> Date: Mon, 19 Aug 2024 03:54:30 +0200 Subject: [PATCH] Convert Label to TypeScript (cherry picked from commit 3eca63a67c898256b711d37607f07cbabb9ed323) Closes #10308 --- frontend/src/Components/Label.js | 52 ------------------- frontend/src/Components/Label.tsx | 31 +++++++++++ .../src/Helpers/Props/{kinds.js => kinds.ts} | 4 +- .../src/Helpers/Props/{sizes.js => sizes.ts} | 9 +++- 4 files changed, 41 insertions(+), 55 deletions(-) delete mode 100644 frontend/src/Components/Label.js create mode 100644 frontend/src/Components/Label.tsx rename frontend/src/Helpers/Props/{kinds.js => kinds.ts} (96%) rename frontend/src/Helpers/Props/{sizes.js => sizes.ts} (66%) diff --git a/frontend/src/Components/Label.js b/frontend/src/Components/Label.js deleted file mode 100644 index 4b565f840..000000000 --- a/frontend/src/Components/Label.js +++ /dev/null @@ -1,52 +0,0 @@ -import classNames from 'classnames'; -import PropTypes from 'prop-types'; -import React from 'react'; -import { kinds, sizes } from 'Helpers/Props'; -import styles from './Label.css'; - -function Label(props) { - const { - className, - kind, - size, - outline, - children, - colorImpairedMode, - ...otherProps - } = props; - - return ( - - {children} - - ); -} - -Label.propTypes = { - className: PropTypes.string.isRequired, - title: PropTypes.string, - kind: PropTypes.oneOf(kinds.all).isRequired, - size: PropTypes.oneOf(sizes.all).isRequired, - outline: PropTypes.bool.isRequired, - children: PropTypes.node.isRequired, - colorImpairedMode: PropTypes.bool -}; - -Label.defaultProps = { - className: styles.label, - kind: kinds.DEFAULT, - size: sizes.SMALL, - outline: false, - colorImpairedMode: false -}; - -export default Label; diff --git a/frontend/src/Components/Label.tsx b/frontend/src/Components/Label.tsx new file mode 100644 index 000000000..411cefddf --- /dev/null +++ b/frontend/src/Components/Label.tsx @@ -0,0 +1,31 @@ +import classNames from 'classnames'; +import React, { ComponentProps, ReactNode } from 'react'; +import { kinds, sizes } from 'Helpers/Props'; +import styles from './Label.css'; + +export interface LabelProps extends ComponentProps<'span'> { + kind?: Extract<(typeof kinds.all)[number], keyof typeof styles>; + size?: Extract<(typeof sizes.all)[number], keyof typeof styles>; + outline?: boolean; + children: ReactNode; +} + +export default function Label({ + className = styles.label, + kind = kinds.DEFAULT, + size = sizes.SMALL, + outline = false, + ...otherProps +}: LabelProps) { + return ( + + ); +} diff --git a/frontend/src/Helpers/Props/kinds.js b/frontend/src/Helpers/Props/kinds.ts similarity index 96% rename from frontend/src/Helpers/Props/kinds.js rename to frontend/src/Helpers/Props/kinds.ts index 8b4af1956..9f205dd91 100644 --- a/frontend/src/Helpers/Props/kinds.js +++ b/frontend/src/Helpers/Props/kinds.ts @@ -23,5 +23,5 @@ export const all = [ PURPLE, SUCCESS, WARNING, - QUEUE -]; + QUEUE, +] as const; diff --git a/frontend/src/Helpers/Props/sizes.js b/frontend/src/Helpers/Props/sizes.ts similarity index 66% rename from frontend/src/Helpers/Props/sizes.js rename to frontend/src/Helpers/Props/sizes.ts index 44975bbff..809f0397a 100644 --- a/frontend/src/Helpers/Props/sizes.js +++ b/frontend/src/Helpers/Props/sizes.ts @@ -5,4 +5,11 @@ export const LARGE = 'large'; export const EXTRA_LARGE = 'extraLarge'; export const EXTRA_EXTRA_LARGE = 'extraExtraLarge'; -export const all = [EXTRA_SMALL, SMALL, MEDIUM, LARGE, EXTRA_LARGE, EXTRA_EXTRA_LARGE]; +export const all = [ + EXTRA_SMALL, + SMALL, + MEDIUM, + LARGE, + EXTRA_LARGE, + EXTRA_EXTRA_LARGE, +] as const;