Skip to content

Commit

Permalink
fix(Text): add strike through on text
Browse files Browse the repository at this point in the history
  • Loading branch information
matthprost committed Dec 17, 2024
1 parent 4a04150 commit b92cf10
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-fishes-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/ui": patch
---

Add `strikethrough` prop on `<Text />` component
6 changes: 6 additions & 0 deletions packages/plus/src/components/EstimateCost/Components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ type ItemProps = {
| 'years'
// Allow a string for unit but keep autocomplete for the above values
| (string & NonNullable<unknown>)
/*
* To strike through the price
*/
strikeThrough?: boolean
}

const StyleNoPriceItem = styled(Text)`
Expand Down Expand Up @@ -259,6 +263,7 @@ export const Item = memo(
labelTextVariant, // To change left cell typography variant
labelTextProminence, // To change left cell typography prominence
notice, // To display a gray text below the label
strikeThrough, // To strike through the price
}: ItemProps) => {
const { locales, formatNumber } = useEstimateCost()

Expand Down Expand Up @@ -458,6 +463,7 @@ export const Item = memo(
<>
<StyleNoPriceItem
as="p"
strikeThrough={strikeThrough}
variant={noIterationText ? 'headingSmall' : 'bodyStrong'}
prominence={
computedItemPrice === 0 && computedMaxItemPrice === 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { StoryFn } from '@storybook/react'
import { Stack } from '@ultraviolet/ui'
import type { ComponentProps } from 'react'
import { EstimateCost } from '..'

export const NewPrice: StoryFn<ComponentProps<typeof EstimateCost>> = props => (
<Stack gap={4}>
<EstimateCost {...props} hideOverlay>
<EstimateCost.Item label="New server" price={20} noBorder />
</EstimateCost>

<EstimateCost
{...props}
hideOverlay
hideTotal
description={false}
hideTimeUnit
>
<EstimateCost.Item strikeThrough label="Old server" price={10} noBorder />
</EstimateCost>
</Stack>
)

NewPrice.parameters = {
docs: {
description: {
story: '',
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export { GlobalDiscount } from './GlobalDiscount.stories'
export { LocalDiscount } from './LocalDiscount.stories'
export { NegativeValues } from './NegativeValues.stories'
export { Design } from './Design.stories'
export { NewPrice } from './NewPrice.stories'
8 changes: 8 additions & 0 deletions packages/ui/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const generateStyles = ({
disabled,
italic,
underline,
strikeThrough,
}: {
placement?: PlacementProps
prominence: ProminenceProps
Expand All @@ -45,6 +46,7 @@ const generateStyles = ({
disabled: boolean
italic: boolean
underline: boolean
strikeThrough?: boolean
}): string => {
// stronger is available only for neutral sentiment
const definedProminence =
Expand Down Expand Up @@ -87,6 +89,7 @@ const generateStyles = ({
}
${italic ? `font-style: italic;` : ''}
${underline ? `text-decoration: underline;` : ''}
${strikeThrough ? `text-decoration: line-through;` : ''}
`
}

Expand All @@ -110,6 +113,7 @@ type TextProps = {
dir?: 'ltr' | 'rtl' | 'auto'
htmlFor?: string
'data-testid'?: string
strikeThrough?: boolean
}

const StyledText = styled('div', {
Expand All @@ -124,6 +128,7 @@ const StyledText = styled('div', {
'disabled',
'italic',
'underline',
'strikeThrough',
].includes(prop),
})<{
placement?: PlacementProps
Expand All @@ -135,6 +140,7 @@ const StyledText = styled('div', {
italic: boolean
underline: boolean
htmlFor?: string
strikeThrough?: boolean
}>(generateStyles)

/**
Expand All @@ -153,6 +159,7 @@ export const Text = ({
disabled = false,
italic = false,
underline = false,
strikeThrough = false,
id,
dir,
htmlFor,
Expand All @@ -178,6 +185,7 @@ export const Text = ({
disabled={disabled}
italic={italic}
underline={underline}
strikeThrough={strikeThrough}
id={id}
dir={dir}
htmlFor={htmlFor}
Expand Down

0 comments on commit b92cf10

Please sign in to comment.