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 Jan 6, 2025
1 parent 9fd969e commit 5ef64ca
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
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'
9 changes: 8 additions & 1 deletion packages/ui/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const generateStyles = ({
italic,
underline,
whiteSpace,
strikeThrough,
}: {
placement?: PlacementProps
prominence: ProminenceProps
Expand All @@ -47,6 +48,7 @@ const generateStyles = ({
italic: boolean
underline: boolean
whiteSpace?: WhiteSpaceProps
strikeThrough?: boolean
}): string => {
// stronger is available only for neutral sentiment
const definedProminence =
Expand Down Expand Up @@ -90,7 +92,7 @@ const generateStyles = ({
}
${italic ? `font-style: italic;` : ''}
${underline ? `text-decoration: underline;` : ''}
${strikeThrough ? `text-decoration: line-through;` : ''}
`
}

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

Expand All @@ -129,6 +132,7 @@ const StyledText = styled('div', {
'disabled',
'italic',
'underline',
'strikeThrough',
'whiteSpace',
].includes(prop),
})<{
Expand All @@ -141,6 +145,7 @@ const StyledText = styled('div', {
italic: boolean
underline: boolean
htmlFor?: string
strikeThrough?: boolean
whiteSpace?: WhiteSpaceProps
}>(generateStyles)

Expand All @@ -160,6 +165,7 @@ export const Text = ({
disabled = false,
italic = false,
underline = false,
strikeThrough = false,
id,
dir,
whiteSpace,
Expand All @@ -186,6 +192,7 @@ export const Text = ({
disabled={disabled}
italic={italic}
underline={underline}
strikeThrough={strikeThrough}
id={id}
dir={dir}
htmlFor={htmlFor}
Expand Down

0 comments on commit 5ef64ca

Please sign in to comment.