From 4a288428402ac9518626fc2e4550b090162e2064 Mon Sep 17 00:00:00 2001 From: Marco Vidal Garcia Date: Tue, 17 Oct 2023 17:00:19 +0200 Subject: [PATCH] feat(BadgeList): migrate to Tailwind Closes FEPLT-1685 --- .../src/BadgeList/BadgeListItem/index.js.flow | 4 - .../src/BadgeList/BadgeListItem/index.tsx | 120 ++++++++---------- .../orbit-components/src/BadgeList/index.tsx | 12 +- .../ItineraryBadgeListItem.tsx | 25 ++-- 4 files changed, 65 insertions(+), 96 deletions(-) diff --git a/packages/orbit-components/src/BadgeList/BadgeListItem/index.js.flow b/packages/orbit-components/src/BadgeList/BadgeListItem/index.js.flow index 8f8e73b74f..a544913530 100644 --- a/packages/orbit-components/src/BadgeList/BadgeListItem/index.js.flow +++ b/packages/orbit-components/src/BadgeList/BadgeListItem/index.js.flow @@ -1,6 +1,5 @@ // @flow import * as React from "react"; -import type { StyledComponent } from "styled-components"; import type { Globals } from "../../common/common.js.flow"; @@ -17,8 +16,5 @@ export type Props = {| |}; declare export var getIconColor: (type: Type) => string; -declare export var StyledBadgeListItem: StyledComponent; -declare export var StyledVerticalBadge: StyledComponent; -declare export var StyledBadgeContent: StyledComponent; declare export default React.ComponentType; diff --git a/packages/orbit-components/src/BadgeList/BadgeListItem/index.tsx b/packages/orbit-components/src/BadgeList/BadgeListItem/index.tsx index f66f25f3c6..5028cfe493 100644 --- a/packages/orbit-components/src/BadgeList/BadgeListItem/index.tsx +++ b/packages/orbit-components/src/BadgeList/BadgeListItem/index.tsx @@ -1,28 +1,20 @@ "use client"; import * as React from "react"; -import styled, { css } from "styled-components"; +import cx from "clsx"; import Text from "../../Text"; import { TYPE_OPTIONS, SIZE_OPTIONS } from "../consts"; -import defaultTheme from "../../defaultTheme"; import { ICON_COLORS } from "../../Icon/consts"; -import { right } from "../../utils/rtl"; import type { Props, Type } from "./types"; import type { Props as IconProps } from "../../Icon/types"; -const getBackground = ({ theme, $type }: { theme: typeof defaultTheme; $type?: Type }) => { - const tokens = { - [TYPE_OPTIONS.NEUTRAL]: theme.orbit.paletteCloudLight, - [TYPE_OPTIONS.INFO]: theme.orbit.paletteBlueLight, - [TYPE_OPTIONS.SUCCESS]: theme.orbit.paletteGreenLight, - [TYPE_OPTIONS.WARNING]: theme.orbit.paletteOrangeLight, - [TYPE_OPTIONS.CRITICAL]: theme.orbit.paletteRedLight, - }; - - if (!$type) return null; - - return tokens[$type]; +const BACKGROUND = { + [TYPE_OPTIONS.NEUTRAL]: "bg-badge-neutral-background", + [TYPE_OPTIONS.INFO]: "bg-badge-info-subtle-background", + [TYPE_OPTIONS.SUCCESS]: "bg-badge-success-subtle-background", + [TYPE_OPTIONS.WARNING]: "bg-badge-warning-subtle-background", + [TYPE_OPTIONS.CRITICAL]: "bg-badge-critical-subtle-background", }; export const getIconColor = (type: Type) => { @@ -30,57 +22,47 @@ export const getIconColor = (type: Type) => { return type; }; -export const StyledBadgeListItem = styled.li` - ${({ theme }) => css` - display: flex; - flex-direction: row; - width: 100%; - & + & { - margin-top: ${theme.orbit.spaceXXSmall}; - } - `}; -`; - -StyledBadgeListItem.defaultProps = { - theme: defaultTheme, -}; - -export const StyledVerticalBadge = styled.div<{ $type?: Props["type"] }>` - ${({ theme, $type }) => css` - background: ${getBackground({ theme, $type })}; - display: flex; - align-items: center; - justify-content: center; - margin-${right}: ${theme.orbit.spaceXSmall}; - flex-shrink: 0; - height: ${theme.orbit.heightIconLarge}; - width: ${theme.orbit.widthIconLarge}; - border-radius: ${theme.orbit.borderRadiusCircle}; - svg { - height: ${theme.orbit.heightIconSmall}; - width: ${theme.orbit.widthIconSmall}; - } - `}; -`; +export const ItemWrapper = ({ children, dataTest }) => ( +
  • + {children} +
  • +); -StyledVerticalBadge.defaultProps = { - theme: defaultTheme, +export const VerticalBadge = ({ + children, + type, +}: { + children: React.ReactNode; + type: Props["type"]; +}) => { + return ( +
    + {children} +
    + ); }; -export const StyledBadgeContent = styled.div` - ${({ theme }) => css` - display: inline-flex; - align-items: center; - - .orbit-tooltip-wrapper .orbit-text { - font-weight: ${theme.orbit.fontWeightMedium}; - } - `}; -`; - -StyledBadgeContent.defaultProps = { - theme: defaultTheme, -}; +export const BadgeContent = ({ + children, + style, +}: { + children: React.ReactNode; + style?: React.CSSProperties; +}) => ( +
    + {children} +
    +); const BadgeListItem = ({ icon, @@ -91,19 +73,19 @@ const BadgeListItem = ({ children, }: Props) => { return ( - - + + {React.isValidElement(icon) && React.cloneElement(icon as React.ReactElement, { color: getIconColor(type), })} - - + + {children} - - + + ); }; diff --git a/packages/orbit-components/src/BadgeList/index.tsx b/packages/orbit-components/src/BadgeList/index.tsx index c42f84099d..e6bbbffd29 100644 --- a/packages/orbit-components/src/BadgeList/index.tsx +++ b/packages/orbit-components/src/BadgeList/index.tsx @@ -1,22 +1,14 @@ "use client"; import * as React from "react"; -import styled from "styled-components"; import type { Props } from "./types"; -const StyledBadgeList = styled.ul` - margin: 0; - padding: 0; - display: flex; - flex-direction: column; -`; - const BadgeList = ({ children, dataTest, id }: Props) => { return ( - +
      {children} - +
    ); }; diff --git a/packages/orbit-components/src/Itinerary/ItineraryBadgeList/ItineraryBadgeListItem.tsx b/packages/orbit-components/src/Itinerary/ItineraryBadgeList/ItineraryBadgeListItem.tsx index 2e6793e128..095bd3f4c9 100644 --- a/packages/orbit-components/src/Itinerary/ItineraryBadgeList/ItineraryBadgeListItem.tsx +++ b/packages/orbit-components/src/Itinerary/ItineraryBadgeList/ItineraryBadgeListItem.tsx @@ -1,13 +1,12 @@ "use client"; import * as React from "react"; -import { css } from "styled-components"; import { - StyledBadgeListItem, + ItemWrapper, getIconColor, - StyledVerticalBadge, - StyledBadgeContent, + VerticalBadge, + BadgeContent, } from "../../BadgeList/BadgeListItem"; import Stack from "../../Stack"; // TODO: remove after designers will resolve status colors @@ -25,15 +24,15 @@ const ItineraryBadgeListItem = ({ strikeThrough, }: Props) => { return ( - - + + {/* @ts-expect-error TODO */} {React.isValidElement(icon) && React.cloneElement(icon, { color: getIconColor(type) })} - - + )} - - + + ); };