Skip to content

Commit

Permalink
Refactor(web-react): Card use DirectionExtended Dictionary
Browse files Browse the repository at this point in the history
- Solves #DS-1649
  • Loading branch information
pavelklibani committed Jan 29, 2025
1 parent bad4fba commit 214ef37
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
UseCardStyleProps,
} from '../../../src/components';
import { LOGO, MEDIA_IMAGE } from '../../../src/components/Card/demo/constants';
import { AlignmentX, Sizes } from '../../../src/constants';
import { CardDirection, CardSizes, GridColumns, SizesDictionaryType } from '../../../src/types';
import { AlignmentX, DirectionExtended, Sizes } from '../../../src/constants';
import { CardSizes, GridColumns, SizesDictionaryType } from '../../../src/types';

type CardCompositionType = {
cardElementType: ElementType;
Expand Down Expand Up @@ -97,10 +97,10 @@ export default {
direction: {
control: 'select',
description: 'Direction of the card.',
options: [...Object.values(CardDirection)],
options: [...Object.values(DirectionExtended)],
table: {
category: 'Card',
defaultValue: { summary: CardDirection.VERTICAL },
defaultValue: { summary: DirectionExtended.VERTICAL },
},
},
eyebrowText: {
Expand Down Expand Up @@ -295,7 +295,7 @@ export default {
cardLogoSize: Sizes.MEDIUM,
contentText:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, nulla nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat. Morbi fringilla convallis sapien. Sed ac felis. Aliquam erat volutpat. Aliquam euismod. Aenean vel lectus. Nunc imperdiet justo nec dolor.',
direction: CardDirection.VERTICAL,
direction: DirectionExtended.VERTICAL,
eyebrowText: 'Eyebrow title',
footerAlignmentX: AlignmentX.LEFT,
gridCols: 3,
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import classNames from 'classnames';
import React, { ElementType } from 'react';
import { Direction } from '../../constants';
import { DirectionExtended } from '../../constants';
import { useStyleProps } from '../../hooks';
import { SpiritCardProps } from '../../types';
import { useCardStyleProps } from './useCardStyleProps';

const defaultProps: Partial<SpiritCardProps> = {
direction: Direction.VERTICAL,
direction: DirectionExtended.VERTICAL,
elementType: 'article',
isBoxed: false,
};
Expand Down
10 changes: 5 additions & 5 deletions packages/web-react/src/components/Card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ Card can be displayed with a border and a box shadow on hover.

### API

| Name | Type | Default | Required | Description |
| ------------- | ---------------------------------------------------------------------------------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `direction` | \[[Direction dictionary][dictionary-direction], `horizontal-reversed` \| `object`] | `vertical` || Direction of the content inside Card component, use object to set responsive values, e.g. `{ mobile: 'horizontal', tablet: 'vertical', desktop: 'horizontal-reversed' }` |
| `elementType` | `ElementType` | `article` || Type of element |
| `isBoxed` | `bool` | `false` || Whether the Card have border |
| Name | Type | Default | Required | Description |
| ------------- | ------------------------------------------------------------------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `direction` | \[[DirectionExtended dictionary][dictionary-direction] \| `object`] | `vertical` || Direction of the content inside Card component, use object to set responsive values, e.g. `{ mobile: 'horizontal', tablet: 'vertical', desktop: 'horizontal-reversed' }` |
| `elementType` | `ElementType` | `article` || Type of element |
| `isBoxed` | `bool` | `false` || Whether the Card have border |

On top of the API options, the components accept [additional attributes][readme-additional-attributes].
If you need more control over the styling of a component, you can use [style props][readme-style-props]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AlignmentX } from '../../../../constants';
import { AlignmentXDictionaryType, CardDirection, CardSizes } from '../../../../types';
import { AlignmentX, DirectionExtended } from '../../../../constants';
import { AlignmentXDictionaryType, CardSizes } from '../../../../types';
import { toPascalCase } from '../../../../utils';
import { UseCardStyleProps, UseCardStylePropsReturn } from '../../useCardStyleProps';

Expand Down Expand Up @@ -53,17 +53,17 @@ const sizeDataProvider = Object.values(CardSizes).map((size) => ({
export const textPropsDataProvider: TextPropsDataProviderType[] = [
// Direction-specific classes
{
props: { direction: CardDirection.VERTICAL },
props: { direction: DirectionExtended.VERTICAL },
description: 'return correct classProps for direction vertical',
expected: { classProps: generateExpectedClassProps({ root: 'Card Card--vertical' }) },
},
{
props: { direction: CardDirection.HORIZONTAL },
props: { direction: DirectionExtended.HORIZONTAL },
description: 'return correct classProps for direction horizontal',
expected: { classProps: generateExpectedClassProps({ root: 'Card Card--horizontal' }) },
},
{
props: { direction: CardDirection.HORIZONTAL_REVERSED },
props: { direction: DirectionExtended.HORIZONTAL_REVERSED },
description: 'return correct classProps for direction horizontal reversed',
expected: { classProps: generateExpectedClassProps({ root: 'Card Card--horizontalReversed' }) },
},
Expand Down Expand Up @@ -136,7 +136,7 @@ export const textPropsDataProvider: TextPropsDataProviderType[] = [
{
props: {
artworkAlignmentX: AlignmentX.LEFT,
direction: CardDirection.HORIZONTAL,
direction: DirectionExtended.HORIZONTAL,
footerAlignmentX: AlignmentX.RIGHT,
hasFilledHeight: true,
isBoxed: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { CardDirection } from '../../../types';
import { DirectionExtended } from '../../../constants';
import { ButtonLink } from '../../ButtonLink';
import { Container } from '../../Container';
import { PartnerLogo } from '../../PartnerLogo';
Expand All @@ -27,9 +27,9 @@ const meta: Meta<typeof Card> = {
direction: {
control: 'select',
description: 'Direction of the card.',
options: [...Object.values(CardDirection)],
options: [...Object.values(DirectionExtended)],
table: {
defaultValue: { summary: CardDirection.VERTICAL },
defaultValue: { summary: DirectionExtended.VERTICAL },
},
},
elementType: {
Expand All @@ -44,7 +44,7 @@ const meta: Meta<typeof Card> = {
},
},
args: {
direction: CardDirection.VERTICAL,
direction: DirectionExtended.VERTICAL,
elementType: 'article',
isBoxed: false,
},
Expand Down
17 changes: 4 additions & 13 deletions packages/web-react/src/types/card.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ElementType, JSXElementConstructor } from 'react';
import { Direction, Sizes } from '../constants';
import { Sizes } from '../constants';
import {
AlignmentXDictionaryType,
ChildrenProps,
DirectionExtendedDictionaryType,
SpiritPolymorphicElementPropsWithRef,
StyleProps,
TransferProps,
Expand All @@ -16,14 +17,6 @@ export const CardSizes = {
export type CardSizesDictionaryKeys = keyof typeof CardSizes;
export type CardSizesDictionaryType<T = undefined> = (typeof CardSizes)[CardSizesDictionaryKeys] | T;

export const CardDirection = {
...Direction,
HORIZONTAL_REVERSED: 'horizontal-reversed',
};

export type CardDirectionDictionaryKeys = keyof typeof CardDirection;
export type CardDirectionDictionaryType = (typeof CardDirection)[CardDirectionDictionaryKeys];

export type CardAlignmentXType =
| NonNullable<AlignmentXDictionaryType>
| { [key: string]: NonNullable<AlignmentXDictionaryType> };
Expand All @@ -38,11 +31,9 @@ export interface CardElementTypeProps<T extends ElementType = 'article'> {
}

// Card types
// Extend direction props to include horizontal-reversed
export type HorizontalReversedType = 'horizontal-reversed';
export type CardDirectionType =
| NonNullable<CardDirectionDictionaryType>
| { [key: string]: NonNullable<CardDirectionDictionaryType> };
| NonNullable<DirectionExtendedDictionaryType>
| { [key: string]: NonNullable<DirectionExtendedDictionaryType> };

export interface CardProps<T extends ElementType = 'article'> extends CardElementTypeProps<T> {
direction?: CardDirectionType;
Expand Down

0 comments on commit 214ef37

Please sign in to comment.