Skip to content

Commit

Permalink
fix: better styles for size:'s'
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Mar 11, 2024
1 parent ca82aba commit b4c7ebd
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 5 deletions.
17 changes: 16 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import '@gravity-ui/uikit/styles/styles.scss';

import {ThemeProvider, MobileProvider, configure as uikitConfigure} from '@gravity-ui/uikit';
import {configure} from '../src/configure';
import {SizeProvider} from '../src/stories/SizeContext';

export const withContextProvider: Decorator = (StoryItem, context) => {
return (
<React.StrictMode>
<ThemeProvider theme={context.globals.theme}>
<MobileProvider>
<StoryItem {...context} />
<SizeProvider value={context.globals.size}>
<StoryItem {...context} />
</SizeProvider>
</MobileProvider>
</ThemeProvider>
</React.StrictMode>
Expand Down Expand Up @@ -62,6 +65,18 @@ const preview: Preview = {
],
},
},
size: {
name: 'Size',
defaultValue: 'm',
toolbar: {
icon: 'apple',
items: [
{title: 's', value: 's'},
{title: 'm', value: 'm'},
{title: 'l', value: 'l'},
],
},
},
},
};

Expand Down
36 changes: 36 additions & 0 deletions src/dialog/Dialog/Dialog.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
.df-dialog {
$self: &;

&.df-dialog_size_s {
#{$self}__field-wrapper {
width: 250px;

&_type_block,
&_type_textarea {
width: 100%;
}

&_type_plain {
padding-top: 6px;
}

&_full-width {
width: 100%;
padding-top: 12px;
}
}
}

&_with_vertical_tabs {
display: flex;

Expand All @@ -13,6 +33,18 @@
width: 100%;
}
}

&.df-dialog_size_s {
#{$self}__field-wrapper {
width: 200px;

&.df-dialog__field-wrapper_type_textarea,
&.df-dialog__field-wrapper_type_block,
&_full-width {
width: 100%;
}
}
}
}

&__caption {
Expand Down Expand Up @@ -216,6 +248,10 @@

--_--side-padding: 32px;

&.df-page-dialog_size_s {
width: 480px;
}

&__wrapper {
width: 100%;
display: flex;
Expand Down
8 changes: 4 additions & 4 deletions src/dialog/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ class Dialog<
form: FormApi<FormValues, InitialFormValues>,
) => {
this.form = form;
const {waitingMessage, headerProps, footerProps, fields, formId} = this.props;
const {waitingMessage, headerProps, footerProps, fields, formId, size} = this.props;
const {verticalTabs} = this.state;
const {title, insertAfter, insertBefore} = headerProps || {};
const {textApply: textApplyDefault, textCancel: textCancelDefault} =
Expand Down Expand Up @@ -1092,7 +1092,7 @@ class Dialog<
<CommonDialog.Body
className={bDialog('body', {with_vertical_tabs: Boolean(verticalTabs)})}
>
<div className={bDialog({with_vertical_tabs: Boolean(verticalTabs)})}>
<div className={bDialog({size, with_vertical_tabs: Boolean(verticalTabs)})}>
{isArrayOfTabs(fields) ? (
this.renderTabbedFields()
) : (
Expand Down Expand Up @@ -1137,10 +1137,10 @@ class Dialog<
handleSubmit: () => void;
form: FormApi<FormValues, InitialFormValues>;
}): React.ReactNode => {
const {className, modal} = this.props;
const {className, modal, size} = this.props;
return (
<div className={bPage('wrapper', {modal}, className)}>
<div className={bPage()}>{this.renderDialogContent(handleSubmit, form)}</div>
<div className={bPage({size})}>{this.renderDialogContent(handleSubmit, form)}</div>
</div>
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/stories/SizeContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

const SizeContext = React.createContext<'s' | 'm' | 'l'>('m');

export const SizeProvider = SizeContext.Provider;

export function useSize() {
const size = React.useContext(SizeContext);
return {size};
}
2 changes: 2 additions & 0 deletions src/stories/dialog/00_Base_controls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {MultiTextControlProps} from '../../dialog/MultiTextControl/MultiTextCont
import {EditableListProps} from '../../dialog/EditableList/EditableList';
import {EditableManyListsProps} from '../../dialog/EditableManyLists/EditableManyLists';
import {SelectControlProps} from '../../dialog/SelectControl/SelectControl';
import {useSize} from '../SizeContext';

class DialogWithSelectStories extends Component {
state = {
Expand Down Expand Up @@ -88,6 +89,7 @@ function DialogDemo({
}}
onClose={onClose ?? (() => {})}
visible
{...useSize()}
onAdd={onAdd}
initialValues={{
plain: 'Some text for "plain" control',
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/01_One_tab.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
firstName: string;
Expand Down Expand Up @@ -66,6 +67,7 @@ function DialogDemo({
headerProps={{
title: 'One tab',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/02_Several_tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -84,6 +85,7 @@ function DialogDemo({
headerProps={{
title: 'Several tabs',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/03_Sections.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
firstName: string;
Expand Down Expand Up @@ -66,6 +67,7 @@ function DialogDemo({
headerProps={{
title: 'Group of fields',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/04_Visibility_condition.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DeepPartial, DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -86,6 +87,7 @@ function DialogDemo({
headerProps={{
title: 'Visibility contdition',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/05_Extras_and_linked_fields.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
type: Array<string>;
Expand Down Expand Up @@ -64,6 +65,7 @@ function DialogDemo({
headerProps={{
title: 'Linked fields by value',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/06_Field_validators.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -84,6 +85,7 @@ function DialogDemo({
headerProps={{
title: 'Field-level validation',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/07_Form_validation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DeepPartial, DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -80,6 +81,7 @@ function DialogDemo({
headerProps={{
title: 'Form-level validation',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/08_Virtualized_tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DeepPartial, DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -74,6 +75,7 @@ function DialogDemo({
headerProps={{
title: 'Virtualized tabs',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/dialog/09_Cloneable_tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DeepPartial, DFDialog} from '../../dialog/Dialog/Dialog';
import {StoryFn, Meta} from '@storybook/react';
import {FormApi} from '../../index';
import {Button} from '@gravity-ui/uikit';
import {useSize} from '../SizeContext';

interface FormValues {
general: {
Expand Down Expand Up @@ -74,6 +75,7 @@ function DialogDemo({
headerProps={{
title: 'Clonable tabs',
}}
{...useSize()}
onClose={onClose ?? (() => {})}
visible
onAdd={onAdd}
Expand Down

0 comments on commit b4c7ebd

Please sign in to comment.