From 17a4b5532bf013071119429711dad21ddc66645d Mon Sep 17 00:00:00 2001 From: Adrian Contiu Date: Fri, 30 Aug 2024 11:54:08 +0300 Subject: [PATCH] [FX-5656] Migrate Rating to TailwindCSS (#4512) --- .changeset/moody-buckets-nail.md | 9 +++ packages/base/Rating/package.json | 8 +-- .../base/Rating/src/RatingIcon/RatingIcon.tsx | 18 ++---- .../RatingIcon/__snapshots__/test.tsx.snap | 2 +- packages/base/Rating/src/RatingIcon/styles.ts | 13 ---- .../Rating/src/RatingStars/RatingStars.tsx | 18 ++---- .../RatingStars/__snapshots__/test.tsx.snap | 32 +++++----- .../base/Rating/src/RatingStars/styles.ts | 14 ----- .../Rating/src/RatingThumbs/RatingThumbs.tsx | 29 ++++----- .../base/Rating/src/RatingThumbs/styles.ts | 59 ++++++++----------- packages/base/Rating/tsconfig.json | 1 + .../src/Rating/__snapshots__/test.tsx.snap | 44 +++++++------- 12 files changed, 96 insertions(+), 151 deletions(-) create mode 100644 .changeset/moody-buckets-nail.md delete mode 100644 packages/base/Rating/src/RatingIcon/styles.ts delete mode 100644 packages/base/Rating/src/RatingStars/styles.ts diff --git a/.changeset/moody-buckets-nail.md b/.changeset/moody-buckets-nail.md new file mode 100644 index 0000000000..cf43871c93 --- /dev/null +++ b/.changeset/moody-buckets-nail.md @@ -0,0 +1,9 @@ +--- +'@toptal/picasso-rating': major +'@toptal/picasso': patch +--- + +### Rating + +- migrate to TailwindCSS, material-ui@4 is no longer required for this package +- make @toptal/picasso-tailwind-merge a peer dependency diff --git a/packages/base/Rating/package.json b/packages/base/Rating/package.json index 720b7e72e0..e839c0291c 100644 --- a/packages/base/Rating/package.json +++ b/packages/base/Rating/package.json @@ -24,15 +24,14 @@ "dependencies": { "@toptal/picasso-container": "3.0.0", "@toptal/picasso-icons": "1.6.0", - "@toptal/picasso-utils": "1.0.3", - "classnames": "^2.5.1" + "@toptal/picasso-utils": "1.0.3" }, "sideEffects": [ "**/styles.ts", "**/styles.js" ], "peerDependencies": { - "@material-ui/core": "4.12.4", + "@toptal/picasso-tailwind-merge": "^2.0.0", "@toptal/picasso-tailwind": ">=2.7", "react": ">=16.12.0 < 19.0.0" }, @@ -40,7 +39,8 @@ ".": "./dist-package/src/index.js" }, "devDependencies": { - "@toptal/picasso-test-utils": "1.1.1" + "@toptal/picasso-test-utils": "1.1.1", + "@toptal/picasso-tailwind-merge": "2.0.0" }, "files": [ "dist-package/**", diff --git a/packages/base/Rating/src/RatingIcon/RatingIcon.tsx b/packages/base/Rating/src/RatingIcon/RatingIcon.tsx index 19ff11dd53..c9a00244bf 100644 --- a/packages/base/Rating/src/RatingIcon/RatingIcon.tsx +++ b/packages/base/Rating/src/RatingIcon/RatingIcon.tsx @@ -1,10 +1,7 @@ import React, { forwardRef } from 'react' -import { makeStyles } from '@material-ui/core/styles' -import cx from 'classnames' import type { SizeType } from '@toptal/picasso-shared' import { Star16, StarSolid16, Star24, StarSolid24 } from '@toptal/picasso-icons' - -import styles from './styles' +import { twJoin } from '@toptal/picasso-tailwind-merge' export interface Props { active: boolean @@ -13,10 +10,6 @@ export interface Props { size: SizeType<'small' | 'large'> } -const useStyles = makeStyles(styles, { - name: 'PicassoRatingIcon', -}) - const iconsBySize = { small: [Star16, StarSolid16], large: [Star24, StarSolid24], @@ -27,13 +20,12 @@ const RatingIcon = forwardRef(function RatingIcon( ref ) { const { active, hovered, interactive, size, ...rest } = props - const classes = useStyles() const iconColor = 'yellow' - const iconClasses = cx({ - [classes.clickableIcon]: interactive, - [classes.hovered]: hovered, - }) + const iconClasses = twJoin( + interactive && 'transition-all duration-350 ease-out hover:scale-150', + hovered && 'scale-150' + ) const [Icon, IconSolid] = iconsBySize[size] || iconsBySize.small return ( diff --git a/packages/base/Rating/src/RatingIcon/__snapshots__/test.tsx.snap b/packages/base/Rating/src/RatingIcon/__snapshots__/test.tsx.snap index 084cdad0db..acad53ad36 100644 --- a/packages/base/Rating/src/RatingIcon/__snapshots__/test.tsx.snap +++ b/packages/base/Rating/src/RatingIcon/__snapshots__/test.tsx.snap @@ -7,7 +7,7 @@ exports[`RatingIcon renders 1`] = ` > diff --git a/packages/base/Rating/src/RatingIcon/styles.ts b/packages/base/Rating/src/RatingIcon/styles.ts deleted file mode 100644 index ad59c3644f..0000000000 --- a/packages/base/Rating/src/RatingIcon/styles.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { Theme } from '@material-ui/core/styles' -import { createStyles } from '@material-ui/core/styles' - -export default ({ transitions }: Theme) => - createStyles({ - clickableIcon: { - transition: `all ${transitions.duration.short}ms ${transitions.easing.easeOut}`, - '&:hover, &$hovered': { - transform: 'scale(1.5)', - }, - }, - hovered: {}, - }) diff --git a/packages/base/Rating/src/RatingStars/RatingStars.tsx b/packages/base/Rating/src/RatingStars/RatingStars.tsx index c820dc9906..297a0e50cb 100644 --- a/packages/base/Rating/src/RatingStars/RatingStars.tsx +++ b/packages/base/Rating/src/RatingStars/RatingStars.tsx @@ -1,12 +1,10 @@ import type { ReactNode, ChangeEvent } from 'react' import React, { forwardRef, useCallback } from 'react' import type { BaseProps, SizeType } from '@toptal/picasso-shared' -import { makeStyles } from '@material-ui/core/styles' -import cx from 'classnames' import { Container } from '@toptal/picasso-container' +import { twJoin } from '@toptal/picasso-tailwind-merge' import { RatingIcon } from '../RatingIcon' -import styles from './styles' export interface Props extends BaseProps { /** Value of the name attribute of the rating input */ @@ -25,10 +23,6 @@ export interface Props extends BaseProps { size?: SizeType<'small' | 'large'> } -const useStyles = makeStyles(styles, { - name: 'PicassoRating', -}) - const RatingStars = forwardRef(function RatingStars( props, ref @@ -44,8 +38,6 @@ const RatingStars = forwardRef(function RatingStars( ...rest } = props - const classes = useStyles() - const handleChange = useCallback( (event: ChangeEvent) => { if (onChange && interactive) { @@ -82,9 +74,7 @@ const RatingStars = forwardRef(function RatingStars( @@ -109,7 +99,7 @@ const RatingStars = forwardRef(function RatingStars( id={resetInputId} value='' onChange={handleChange} - className={classes.radio} + className='hidden' /> ) diff --git a/packages/base/Rating/src/RatingStars/__snapshots__/test.tsx.snap b/packages/base/Rating/src/RatingStars/__snapshots__/test.tsx.snap index 086c6357ce..41ea2be78b 100644 --- a/packages/base/Rating/src/RatingStars/__snapshots__/test.tsx.snap +++ b/packages/base/Rating/src/RatingStars/__snapshots__/test.tsx.snap @@ -9,12 +9,12 @@ exports[`Rating.Stars renders 1`] = ` class="" > @@ -24,7 +24,7 @@ exports[`Rating.Stars renders 1`] = ` - createStyles({ - radio: { - display: 'none', - }, - label: { - marginRight: '.125rem', - }, - clickableLabel: { - cursor: 'pointer', - }, - }) diff --git a/packages/base/Rating/src/RatingThumbs/RatingThumbs.tsx b/packages/base/Rating/src/RatingThumbs/RatingThumbs.tsx index a47a53b958..77fae1c6b0 100644 --- a/packages/base/Rating/src/RatingThumbs/RatingThumbs.tsx +++ b/packages/base/Rating/src/RatingThumbs/RatingThumbs.tsx @@ -1,7 +1,4 @@ -import type { Theme } from '@material-ui/core/styles' -import { makeStyles } from '@material-ui/core/styles' import type { BaseProps, SizeType } from '@toptal/picasso-shared' -import classNames from 'classnames' import type { ChangeEvent } from 'react' import React, { forwardRef, useCallback, useState } from 'react' import { @@ -12,7 +9,7 @@ import { } from '@toptal/picasso-icons' import { Container } from '@toptal/picasso-container' -import styles from './styles' +import { getThumbClasses, labelClasses } from './styles' type Size = SizeType<'small' | 'large'> @@ -49,8 +46,6 @@ export interface Props extends BaseProps { } } -const useStyles = makeStyles(styles) - const enum ThumbsValue { POSITIVE = 'positive', NEGATIVE = 'negative', @@ -68,8 +63,6 @@ export const RatingThumbs = forwardRef( { name, interactive = true, size = 'small', value, onChange, testIds = {} }, ref ) { - const classes = useStyles() - const [baseUniqueId] = useState(() => globalId++) const positiveInputId = `${baseUniqueId}-posititve` @@ -88,17 +81,14 @@ export const RatingThumbs = forwardRef( return ( -