Skip to content

Commit

Permalink
Fix Price align
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Naszalyi committed Nov 12, 2024
1 parent a6525d6 commit c80d189
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
8 changes: 4 additions & 4 deletions examples/react-template/screens/Price.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Columns, ColumnsItem, TrilogyColor } from '@trilogy-ds/react'
import { Alignable, Columns, ColumnsItem, TrilogyColor } from '@trilogy-ds/react'
import {
Divider,
Price,
Expand All @@ -19,9 +19,9 @@ export const PriceScreen = (): JSX.Element => {
Prix classiques seuls
</Title>
<Spacer size={SpacerSize.FIVE} />
<Columns>
<ColumnsItem narrow>
<Price amount={10.99} level={1} />
<Columns multiline>
<ColumnsItem size={4}>
<Price amount={10.99} level={1} align={Alignable.ALIGNED_CENTER} />
</ColumnsItem>
<ColumnsItem narrow>
<Price amount={10.99} level={1} hideCents />
Expand Down
33 changes: 15 additions & 18 deletions packages/react/components/price/Price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ const Price = ({
),
)

const priceParentNode = hashClass(
styled,
clsx(
(align == Alignable.ALIGNED_START && has('text-left')) ||
(align == Alignable.ALIGNED_CENTER && has('text-centered')) ||
(align == Alignable.ALIGNED_END && has('text-right')) ||
'',
),
)

let amountComponent = null
let oldAmountComponent = null
let tagAmountComponent = null
Expand Down Expand Up @@ -148,21 +138,28 @@ const Price = ({
)
}

const returnComponent = (
<div id={id} className={hashClass(styled, clsx('price-container', is(`level-${level || '1'}`)))}>
return (
<div
id={id}
className={hashClass(
styled,
clsx(
'price-container',
is(`level-${level || '1'}`),
(align == Alignable.ALIGNED_START && is('justified-left')) ||
(align == Alignable.ALIGNED_CENTER && is('justified-center')) ||
(align == Alignable.ALIGNED_END && is('justified-right')) ||
'',
),
)}
>
{overline && <p className={hashClass(styled, clsx('overline'))}>{overline}</p>}
{oldAmountComponent}
{amountComponent}
{tagAmountComponent}
{accessibilityLabel && <p className='sr-only'>{accessibilityLabel}</p>}
</div>
)

if (align) {
return <div className={priceParentNode}>{returnComponent}</div>
}

return returnComponent
}

export default Price

0 comments on commit c80d189

Please sign in to comment.