Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FormRow): add direction prop #104

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/components/FormRow/FormRow.scss
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
@use '../variables';

.#{variables.$ns}form-row {
$block: '.#{variables.$ns}form-row';

#{$block} {
--gc-form-row-label-width: 172px;
--gc-form-row-field-height: 28px;

margin-bottom: 20px;
align-items: flex-start;
display: flex;
margin-bottom: 20px;

&_direction_row {
Copy link
Contributor

Choose a reason for hiding this comment

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

put modifiers inside element selectors pls

&__left {
  #{$block}_direction_row & {}
  #{$block}_direction_column & {}
}

align-items: flex-start;
}

&_direction_column {
flex-direction: column;
}

&__left {
display: flex;
flex-flow: row;
min-height: var(--gc-form-row-field-height);
box-sizing: border-box;
flex-shrink: 0;
width: var(--gc-form-row-label-width);
padding-right: 8px;

#{$block}_direction_row & {
min-height: var(--gc-form-row-field-height);
flex-shrink: 0;
width: var(--gc-form-row-label-width);
padding-right: 8px;
}

#{$block}_direction_column & {
width: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this required with display: flex?

margin-bottom: 10px;
}
}

&__field-name {
Expand Down
3 changes: 2 additions & 1 deletion src/components/FormRow/FormRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ const FormRowComponent: FC<FormRowProps> = ({
fieldId,
required = false,
children,
direction = 'row',
}) => {
const LabelComponent = fieldId ? 'label' : 'span';

return (
<div className={b(null, className)}>
<div className={b({direction}, className)}>
<div className={b('left')}>
<LabelComponent className={b('field-name')} htmlFor={fieldId ? fieldId : undefined}>
<span className={b('field-name-text')}>{label}</span>
Expand Down
6 changes: 6 additions & 0 deletions src/components/FormRow/__stories__/FormRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
label: 'Enter your name',
fieldId,
children: <TextInput id={fieldId} />,
direction: 'row',
},
argTypes: {
children: argTypeReactNode,
Expand Down Expand Up @@ -88,3 +89,8 @@ WithHelpPopoverAndLongLabel.args = {
...WithLongLabel.args,
...WithHelpPopover.args,
};

export const ColumnDirection = Template.bind({});
ColumnDirection.args = {
direction: 'column',
};
4 changes: 4 additions & 0 deletions src/components/FormRow/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type {HTMLAttributes, PropsWithChildren, ReactNode} from 'react';

export type FormRowDirection = 'row' | 'column';

export interface FormRowProps {
className?: string;
/** Field label */
Expand All @@ -13,6 +15,8 @@ export interface FormRowProps {
/** Field component itself. `<FormRow.FieldDescription/>` could be used here
* next to field component itself */
children?: ReactNode;
/** Direction in which the elements are placed */
direction?: FormRowDirection;
}

export type FormRowFieldDescriptionProps = PropsWithChildren<{}> &
Expand Down
Loading