Skip to content

Commit

Permalink
chore[DST-69]: added width as style prop from tailwind (#3233)
Browse files Browse the repository at this point in the history
* added style prop from tailwind

* add new type to components

* save

* save mdx files

* tests

* test
  • Loading branch information
sarahgm authored Jul 28, 2023
1 parent 7b7348f commit 5942d94
Show file tree
Hide file tree
Showing 34 changed files with 162 additions and 102 deletions.
6 changes: 3 additions & 3 deletions docs/content/components/form/autocomplete/autocomplete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ import { Autocomplete } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the `width` of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'menuTrigger',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/checkbox/checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { Checkbox, CheckboxGroup } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'defaultChecked',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/combobox/combobox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ import { ComboBox } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the `width` of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'menuTrigger',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/datefield/datefield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ import { DateField } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
]}
/>
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/number-field/number-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ import { NumberField } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'minValue',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/radio/radio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { Radio } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'disabled',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/search-field/search-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ import { SearchField } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the `width` of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
]}
/>
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/select/select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ import { Select } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Set the width of the select.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'onChange',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/slider/slider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import { Slider } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: '...',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/switch/switch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import { Switch } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the width of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'defaultSelected',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/tag/tag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ import { Tag } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Set the width of the select.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'allowsRemoving',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/text-area/text-area.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ import { TextArea } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Sets the width of the textarea.',
default: 'none',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: 'rows',
Expand Down
6 changes: 3 additions & 3 deletions docs/content/components/form/textfield/textfield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ import { TextField } from '@marigold/components';
},
{
property: 'width',
type: 'string',
description: 'Control the `width` of the field.',
default: '100%',
type: 'string | number',
description: `Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width `,
default: 'full',
},
{
property: '...',
Expand Down
1 change: 0 additions & 1 deletion docs/ui/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { BlankCanvas } from './icons';
export interface PropsTableProps {
props?: { [key: string]: string }[];
}

export const PropsTable = ({ props }: PropsTableProps) => {
return (
<Card px={3} py={4}>
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ListBox } from '../ListBox';
import { Popover } from '../Overlay';

import { ClearButton } from './ClearButton';
import { WidthProp } from '@marigold/system';

// Search Icon
//----------------
Expand Down Expand Up @@ -64,7 +65,7 @@ export interface AutocompleteProps
onSubmit?: (key: Key | null, value: string | null) => void;
variant?: string;
size?: string;
width?: string;
width?: WidthProp['width'];
}

export const Autocomplete = ({
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/Checkbox/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useCheckboxGroupState,
} from '@react-stately/checkbox';
import { AriaCheckboxGroupProps } from '@react-types/checkbox';
import { useStateProps } from '@marigold/system';
import { useStateProps, WidthProp } from '@marigold/system';
import { HtmlProps } from '@marigold/types';
import { FieldBase } from '../FieldBase';

Expand Down Expand Up @@ -40,6 +40,7 @@ export interface CheckboxGroupProps
value?: string[];
defaultValue?: string[];
onChange?: (value: string[]) => void;
width?: WidthProp['width'];
}

// Components
Expand All @@ -50,6 +51,7 @@ export const CheckboxGroup = ({
disabled,
readOnly,
error,
width,
...rest
}: CheckboxGroupProps) => {
const props = {
Expand Down Expand Up @@ -81,6 +83,7 @@ export const CheckboxGroup = ({
errorMessageProps={errorMessageProps}
disabled={disabled}
stateProps={stateProps}
width={width}
{...groupProps}
>
<div role="presentation" className={'flex flex-col items-start'}>
Expand Down
8 changes: 2 additions & 6 deletions packages/components/src/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ test('supports width classname', () => {

// eslint-disable-next-line testing-library/no-node-access
const container = screen.getByText('Label').parentElement;
expect(container?.className).toMatchInlineSnapshot(
`"group/field w-[--fieldWidth]"`
);
expect(container?.className).toMatchInlineSnapshot(`"group/field w-full"`);
});

test('supports classnames', () => {
Expand All @@ -108,9 +106,7 @@ test('supports classnames', () => {
expect(button.className).toMatchInlineSnapshot(
`"inline-flex items-center justify-center gap-[0.5ch] absolute right-2 h-4 w-4 border-none bg-transparent p-0"`
);
expect(container?.className).toMatchInlineSnapshot(
`"group/field w-[--fieldWidth]"`
);
expect(container?.className).toMatchInlineSnapshot(`"group/field w-full"`);
expect(label.className).toMatchInlineSnapshot(
`"text-teal-300 flex w-[var(--labelWidth)]"`
);
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Input } from '../Input';
import { Button } from '../Button';

import { Item } from '@react-stately/collections';
import { WidthProp } from '@marigold/system';

export interface ComboBoxProps
extends Omit<
Expand All @@ -26,7 +27,7 @@ export interface ComboBoxProps
variant?: string;
size?: string;
error?: boolean;
width?: string;
width?: WidthProp['width'];
disabled?: boolean;
required?: boolean;
readOnly?: boolean;
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/DateField/DateField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const meta = {
defaultValue: { summary: 'Something went wrong' },
},
},
width: {
control: {
type: 'text',
},
description: 'Width of the field',
table: {
type: { summary: 'string' },
},
},
required: {
control: {
type: 'boolean',
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/DateField/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useLocale } from '@react-aria/i18n';
import { useDateFieldState } from '@react-stately/datepicker';
import { AriaDateFieldProps, useDateField } from '@react-aria/datepicker';
import { createCalendar, DateValue } from '@internationalized/date';
import { cn, useClassNames, useStateProps } from '@marigold/system';
import { WidthProp, cn, useClassNames, useStateProps } from '@marigold/system';
import { DateSegment } from './DateSegment';
import { FieldBase } from '../FieldBase';
import { mergeProps } from '@react-aria/utils';
Expand Down Expand Up @@ -31,6 +31,7 @@ export interface DateFieldProps
required?: boolean;
variant?: string;
size?: string;
width?: WidthProp['width'];
}

// Component
Expand All @@ -47,6 +48,7 @@ export const DateField = ({
action,
isPressed,
triggerRef,
width,
...res
}: DateFieldProps) => {
const { locale } = useLocale();
Expand Down Expand Up @@ -89,7 +91,6 @@ export const DateField = ({
focus: isFocused || isPressed,
});

console.log(readOnly);
return (
<FieldBase
error={error}
Expand All @@ -103,6 +104,7 @@ export const DateField = ({
stateProps={stateProps}
variant={variant}
size={size}
width={width}
>
<div
{...mergeProps(fieldProps, focusProps, stateProps, hoverProps)}
Expand Down
18 changes: 1 addition & 17 deletions packages/components/src/FieldBase/FieldBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,5 @@ test('takes full width by default', () => {

// eslint-disable-next-line testing-library/no-node-access
const container = screen.getByText('Label').parentElement!;
expect(container.getAttribute('style')).toMatchInlineSnapshot(
`"--fieldWidth: 100%;"`
);
});

test('allows to set custom width', () => {
render(
<FieldBase label="Label" description="Description" width="60px">
<input type="text" />
</FieldBase>
);

// eslint-disable-next-line testing-library/no-node-access
const container = screen.getByText('Label').parentElement!;
expect(container.getAttribute('style')).toMatchInlineSnapshot(
`"--fieldWidth: 60px;"`
);
expect(container.className).toMatchInlineSnapshot(`"group/field w-full"`);
});
17 changes: 10 additions & 7 deletions packages/components/src/FieldBase/FieldBase.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React, { HTMLAttributes, LabelHTMLAttributes, ReactNode } from 'react';
import { StateAttrProps, cn, createVar, useClassNames } from '@marigold/system';
import {
StateAttrProps,
WidthProp,
cn,
useClassNames,
width as twWidth,
} from '@marigold/system';

import { Label, LabelProps } from '../Label';
import { HelpText } from '../HelpText';
import { useFieldGroupContext } from './FieldGroup';

export interface FieldBaseProps {
export interface FieldBaseProps extends WidthProp {
children?: ReactNode;
variant?: string;
size?: string;
width?: string;
disabled?: boolean;
label?: ReactNode;
labelProps?: LabelHTMLAttributes<HTMLLabelElement> & Pick<LabelProps, 'as'>;
Expand All @@ -27,7 +32,7 @@ export const FieldBase = ({
children,
variant,
size,
width = '100%',
width = 'full',
disabled,
label,
labelProps,
Expand All @@ -46,15 +51,13 @@ export const FieldBase = ({
component: 'Field',
variant,
size,
className: 'w-[--fieldWidth]',
});

return (
<div
{...props}
{...stateProps}
className={cn('group/field', classNames)}
style={createVar({ fieldWidth: width })}
className={cn('group/field', twWidth[width], classNames)}
>
{label && (
<Label
Expand Down
Loading

2 comments on commit 5942d94

@vercel
Copy link

@vercel vercel bot commented on 5942d94 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marigold-docs – ./

marigold-docs.vercel.app
marigold-docs-git-main-marigold.vercel.app
marigold-docs-marigold.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5942d94 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marigold-storybook – ./

marigold-latest.vercel.app
marigold-storybook-git-main-marigold.vercel.app
marigold-storybook-marigold.vercel.app

Please sign in to comment.