Skip to content

Commit

Permalink
feat: update FormControl to harmony style
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop authored and asabotovich committed Feb 8, 2024
1 parent 3a7a51b commit e0813ee
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 277 deletions.
20 changes: 20 additions & 0 deletions src/components/CriteriaForm/CriteriaForm.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.SubmitButton {
margin-left: auto;
}

.FormRow {
display: flex;
flex-wrap: nowrap;
margin-top: var(--gap-sm);
}

.FormControl {
display: flex;
align-items: center;
gap: var(--gap-xs);
}

/* Order of styles on page: SC, CSS Modules */
.GoalBadge.GoalBadge {
padding: 0;
}
68 changes: 25 additions & 43 deletions src/components/CriteriaForm/CriteriaForm.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { zodResolver } from '@hookform/resolvers/zod';
import {
AutoCompleteRadioGroup,
nullable,
Form,
Text,
FormControl,
FormControlLabel,
FormControlInput,
FormControlError,
} from '@taskany/bricks';
import { gapSm, gray7 } from '@taskany/colors';
import { AutoCompleteRadioGroup, nullable, Form, Text } from '@taskany/bricks';
import { gray7 } from '@taskany/colors';
import { ComponentProps, forwardRef, useCallback, useEffect, useMemo, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import styled from 'styled-components';
import { z } from 'zod';
import { Button } from '@taskany/bricks/harmony';
import { Button, FormControl, FormControlLabel, FormControlInput, FormControlError } from '@taskany/bricks/harmony';

import { GoalSelect } from '../GoalSelect';
import { GoalBadge } from '../GoalBadge';
Expand All @@ -23,10 +13,7 @@ import { AddInlineTrigger } from '../AddInlineTrigger';
import { StateDot } from '../StateDot';

import { tr } from './CriteriaForm.i18n';

const StyledGoalBadge = styled(GoalBadge)`
padding: 0;
`;
import s from './CriteriaForm.module.css';

interface SuggestItem {
id: string;
Expand Down Expand Up @@ -149,38 +136,26 @@ interface WeightFieldProps extends Pick<ComponentProps<typeof FormControlInput>,
maxValue: number;
}

const StyledFormRow = styled.div`
display: flex;
flex-wrap: nowrap;
margin-top: ${gapSm};
`;

const StyledButton = styled(Button)`
margin-left: auto;
`;

const StyledFormControlInput = styled(FormControlInput)`
width: 3ch;
`;

const CriteriaWeightField = forwardRef<HTMLInputElement, WeightFieldProps>(
({ error, maxValue, value, onChange, name }, ref) => {
return (
<FormControl error={error?.message != null} variant="outline" inline>
<FormControl className={s.FormControl}>
<FormControlLabel color={gray7}>{tr('Weight')}</FormControlLabel>
<StyledFormControlInput
<FormControlInput
outline
size="xs"
value={value}
onChange={onChange}
ref={ref}
autoFocus
autoComplete="off"
name={name}
disabled={maxPossibleWeight === maxValue}
>
{nullable(error, (err) => (
<FormControlError error={err} />
))}
</StyledFormControlInput>
maxLength={3}
style={{ width: error ? '10ch' : '7ch' }}
/>
{nullable(error, (err) => (
<FormControlError error={err} />
))}
<Text size="s" color={gray7}>
{tr.raw('Weight out of', {
upTo: maxPossibleWeight - maxValue,
Expand Down Expand Up @@ -369,7 +344,9 @@ export const CriteriaForm = ({
items={items}
value={value}
onClick={handleSelectItem}
renderItem={(props) => <StyledGoalBadge title={props.item.title} color={props.item.stateColor} />}
renderItem={(props) => (
<GoalBadge title={props.item.title} color={props.item.stateColor} className={s.GoalBadge} />
)}
>
<>
<Controller
Expand Down Expand Up @@ -401,7 +378,7 @@ export const CriteriaForm = ({
/>
))}

<StyledFormRow>
<div className={s.FormRow}>
{nullable(needShowWeightField, () => (
<Controller
name="weight"
Expand All @@ -428,8 +405,13 @@ export const CriteriaForm = ({
/>
))}

<StyledButton type="submit" text={isEditMode ? tr('Save') : tr('Add')} view="primary" />
</StyledFormRow>
<Button
type="submit"
text={isEditMode ? tr('Save') : tr('Add')}
view="primary"
className={s.SubmitButton}
/>
</div>
</>
</GoalSelect>

Expand Down
11 changes: 8 additions & 3 deletions src/components/EstimateDate/EstimateDate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormControl, FormControlInput } from '@taskany/bricks';
import { FormControl, FormControlInput } from '@taskany/bricks/harmony';
import { IconXSolid } from '@taskany/icons';
import { useState, useCallback, useEffect } from 'react';
import InputMask from 'react-input-mask';
Expand Down Expand Up @@ -93,8 +93,13 @@ export const EstimateDate: React.FC = () => {
>
{/* @ts-ignore incorrect type in react-input-mask */}
{(props) => (
<FormControl variant="outline">
<FormControlInput iconRight={<IconXSolid size="xxs" onClick={onRemoveDate} />} {...props} />
<FormControl>
<FormControlInput
outline
size="xs"
iconRight={<IconXSolid size="xxs" onClick={onRemoveDate} />}
{...props}
/>
</FormControl>
)}
</InputMask>
Expand Down
23 changes: 9 additions & 14 deletions src/components/FeedbackCreateForm/FeedbackCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import React, { useCallback, useState } from 'react';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import {
Form,
FormActions,
FormAction,
FormTextarea,
ModalContent,
FormControl,
FormControlInput,
nullable,
FormControlError,
} from '@taskany/bricks';
import { Form, FormActions, FormAction, FormTextarea, ModalContent, nullable } from '@taskany/bricks';
import * as Sentry from '@sentry/nextjs';
import { Button } from '@taskany/bricks/harmony';
import { Button, FormControl, FormControlInput, FormControlError } from '@taskany/bricks/harmony';

import { errorsProvider } from '../../utils/forms';
import { createFeedbackSchema, CreateFeedback } from '../../schema/feedback';
Expand Down Expand Up @@ -64,8 +54,13 @@ const FeedbackCreateForm: React.FC = () => {
return (
<ModalContent>
<Form disabled={formBusy} onSubmit={handleSubmit(onPending, onError)}>
<FormControl flat="bottom" size="l">
<FormControlInput {...register('title')} placeholder={tr('Feedback title')} />
<FormControl>
<FormControlInput
brick="bottom"
size="m"
{...register('title')}
placeholder={tr('Feedback title')}
/>
{nullable(errorsResolver('title'), (error) => (
<FormControlError error={error} />
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ChangeEvent, ComponentProps, ReactNode, useCallback } from 'react';
import styled from 'styled-components';
import { FormControl, FormControlError, FormControlInput, nullable } from '@taskany/bricks';
import { nullable } from '@taskany/bricks';
import { FormControl, FormControlError, FormControlInput } from '@taskany/bricks/harmony';
import { IconSearchOutline } from '@taskany/icons';
import { gapS } from '@taskany/colors';

Expand Down Expand Up @@ -31,8 +32,9 @@ export const FilterAutoCompleteInput: React.FC<FilterAutoCompleteInputProps> = (
);

return (
<StyledFormControl variant="outline" error={error?.message != null}>
<StyledFormControl>
<FormControlInput
outline
autoFocus
placeholder={placeholder}
iconLeft={icon}
Expand Down
23 changes: 9 additions & 14 deletions src/components/FilterCreateForm/FilterCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import React, { useCallback, useState } from 'react';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import {
Form,
FormActions,
FormAction,
FormTextarea,
ModalContent,
FormControl,
FormControlInput,
FormControlError,
nullable,
} from '@taskany/bricks';
import { Form, FormActions, FormTextarea, FormAction, ModalContent, nullable } from '@taskany/bricks';
import * as Sentry from '@sentry/nextjs';
import { Button } from '@taskany/bricks/harmony';
import { Button, FormControl, FormControlInput, FormControlError } from '@taskany/bricks/harmony';

import { errorsProvider } from '../../utils/forms';
import { createFilterSchema, CreateFilter } from '../../schema/filter';
Expand Down Expand Up @@ -71,8 +61,13 @@ const FilterCreateForm: React.FC<FilterCreateFormProps> = ({ mode, params, onSub
<>
<ModalContent>
<Form disabled={formBusy} onSubmit={handleSubmit(onPending, onError)}>
<FormControl brick="right" flat="bottom" size="l">
<FormControlInput {...register('title')} placeholder={tr('Preset title')} />
<FormControl>
<FormControlInput
brick="bottom"
size="m"
{...register('title')}
placeholder={tr('Preset title')}
/>
{nullable(errorsResolver('title'), (error) => (
<FormControlError error={error} />
))}
Expand Down
7 changes: 4 additions & 3 deletions src/components/FlowComboBox.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { ChangeEvent, useState } from 'react';
import { Flow } from '@prisma/client';
import { ComboBox, MenuItem, FormControl, FormControlInput } from '@taskany/bricks';
import { ComboBox, MenuItem } from '@taskany/bricks';
import { IconGitPullOutline } from '@taskany/icons';
import { Button } from '@taskany/bricks/harmony';
import { Button, FormControl, FormControlInput } from '@taskany/bricks/harmony';

import { trpc } from '../utils/trpcClient';

Expand Down Expand Up @@ -44,8 +44,9 @@ export const FlowComboBox = React.forwardRef<HTMLDivElement, FlowComboBoxProps>(
/>
)}
renderInput={(props) => (
<FormControl variant="outline">
<FormControl>
<FormControlInput
outline
autoFocus
disabled={props.disabled}
placeholder={placeholder}
Expand Down
19 changes: 5 additions & 14 deletions src/components/GoalDeleteModal/GoalDeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import React, { ChangeEvent, useCallback, useEffect, useRef, useState } from 'react';
import dynamic from 'next/dynamic';
import { danger0 } from '@taskany/colors';
import {
Text,
Form,
FormAction,
FormActions,
FormTitle,
ModalContent,
ModalHeader,
FormControl,
FormControlInput,
} from '@taskany/bricks';
import { Button } from '@taskany/bricks/harmony';
import { Text, Form, FormAction, FormActions, FormTitle, ModalContent, ModalHeader } from '@taskany/bricks';
import { Button, FormControl, FormControlInput } from '@taskany/bricks/harmony';

import { dispatchModalEvent, ModalEvent } from '../../utils/dispatchModal';
import { goalDeleteForm, goalDeleteShortIdInput, goalDeleteSubmitButton } from '../../utils/domObjects';
Expand Down Expand Up @@ -71,13 +61,14 @@ export const GoalDeleteModal: React.FC<GoalDeleteModalProps> = ({ shortId, onCon
<br />

<Form {...goalDeleteForm.attr}>
<FormControl flat="bottom" size="l">
<FormControl>
<FormControlInput
brick="bottom"
placeholder={shortId}
autoComplete="off"
autoFocus
onChange={onConfirmationInputChange}
ref={ref}
size="m"
{...goalDeleteShortIdInput.attr}
/>
</FormControl>
Expand Down
21 changes: 6 additions & 15 deletions src/components/GoalForm/GoalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ import { useForm, Controller } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Schema, z } from 'zod';
import { State, Tag as TagModel } from '@prisma/client';
import {
Form,
FormActions,
FormAction,
ModalContent,
Tag,
TagCleanButton,
nullable,
FormControl,
FormControlInput,
FormControlError,
} from '@taskany/bricks';
import { Form, FormActions, FormAction, ModalContent, Tag, TagCleanButton, nullable } from '@taskany/bricks';
import { IconCalendarTickOutline } from '@taskany/icons';
import { Button } from '@taskany/bricks/harmony';
import { Button, FormControl, FormControlInput, FormControlError } from '@taskany/bricks/harmony';

import { FormEditor } from '../FormEditor/FormEditor';
import { errorsProvider } from '../../utils/forms';
Expand Down Expand Up @@ -137,16 +126,18 @@ export const GoalForm: React.FC<GoalFormProps> = ({
return (
<ModalContent {...attrs}>
<Form onSubmit={handleSubmit(onSubmit)}>
<FormControl flat="bottom" size="l">
<FormControl>
<FormControlInput
{...register('title')}
disabled={busy}
autoFocus
placeholder={tr("Goal's title")}
brick="bottom"
size="m"
{...goalTitleInput.attr}
/>
{nullable(errorsResolver('title'), (error) => (
<FormControlError error={error} placement="top-start" {...goalTitleInputError.attr} />
<FormControlError error={error} {...goalTitleInputError.attr} />
))}
</FormControl>

Expand Down
7 changes: 4 additions & 3 deletions src/components/GoalParentComboBox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react';
import { ComboBox, FormControl, FormControlError, FormControlInput, nullable } from '@taskany/bricks';
import { Button } from '@taskany/bricks/harmony';
import { ComboBox, nullable } from '@taskany/bricks';
import { Button, FormControl, FormControlError, FormControlInput } from '@taskany/bricks/harmony';

import { useLocalStorage } from '../hooks/useLocalStorage';
import { trpc } from '../utils/trpcClient';
Expand Down Expand Up @@ -69,7 +69,7 @@ export const GoalParentComboBox = React.forwardRef<HTMLDivElement, GoalParentCom
}, []);

return (
<FormControl variant="outline" {...combobox.attr}>
<FormControl {...combobox.attr}>
<ComboBox
ref={ref}
text={value ? `#${value?.id}` : text}
Expand Down Expand Up @@ -99,6 +99,7 @@ export const GoalParentComboBox = React.forwardRef<HTMLDivElement, GoalParentCom
renderInput={(props) => (
<FormControlInput
autoFocus
outline
placeholder={placeholder}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setInputState(e.currentTarget.value);
Expand Down
Loading

0 comments on commit e0813ee

Please sign in to comment.