generated from kubefirst/react-app-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: create text area comp * chore: create tag and environment select * chore: add createEnvironmentMenu comp * fix: keep backdrop but make backdrop transparent so drawer component click away listener will register and close drawer * chore: add createEnvironmentMenu to cluster creation form. * fix: not placing modal so high as to not cause issues with other components such as drawer and its children. pass override styles for further customization * refactor: update ClusterEnvironment type and all dependents * fix: improper name
- Loading branch information
Showing
30 changed files
with
846 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
components/controlledFields/environmentSelect/environmentSelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState } from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import { CreateEnvironmentMenu } from '../../createEnvironmentMenu'; | ||
import Modal from '../../modal'; | ||
import useModal from '../../../hooks/useModal'; | ||
import { ClusterEnvironment } from '../../../types/provision'; | ||
|
||
import ControlledEnvironmentSelect from './index'; | ||
|
||
const meta: Meta<typeof ControlledEnvironmentSelect> = { | ||
component: ControlledEnvironmentSelect, | ||
}; | ||
|
||
export default meta; | ||
|
||
const previouslyCreatedEnvironment: ClusterEnvironment = { | ||
environmentName: 'development', | ||
description: 'Environment for development', | ||
labelColor: 'dark-sky-blue', | ||
}; | ||
|
||
const ControlledEnvironmentSelectWithHooks = () => { | ||
const { isOpen, openModal, closeModal } = useModal(false); | ||
|
||
const [environments, setEnvironments] = useState<ClusterEnvironment[]>([ | ||
previouslyCreatedEnvironment, | ||
]); | ||
|
||
const { | ||
control, | ||
setValue, | ||
formState: { errors }, | ||
} = useForm<{ environment: ClusterEnvironment }>({ | ||
mode: 'onBlur', | ||
}); | ||
|
||
const handleAddEnvironment = (environment: ClusterEnvironment) => { | ||
setEnvironments((curState) => [...curState, environment]); | ||
setValue('environment', environment); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ControlledEnvironmentSelect | ||
control={control} | ||
rules={{ | ||
required: 'environment is required', | ||
}} | ||
name="environment" | ||
label="Environment cluster will host" | ||
required | ||
onErrorText={errors.environment?.message} | ||
options={environments} | ||
onAddNewEnvironment={openModal} | ||
/> | ||
<Modal | ||
padding={0} | ||
isOpen={isOpen} | ||
styleOverrides={{ width: '100%', maxWidth: '630px' }} | ||
onCloseModal={closeModal} | ||
> | ||
<CreateEnvironmentMenu | ||
onSubmit={handleAddEnvironment} | ||
onClose={closeModal} | ||
previouslyCreatedEnvironments={environments} | ||
/> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export const Default: StoryObj<typeof ControlledEnvironmentSelect> = { | ||
render: () => <ControlledEnvironmentSelectWithHooks />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { Control, Controller, UseControllerProps, FieldValues } from 'react-hook-form'; | ||
|
||
import { EnvironmentSelectWithRef } from '../../select/'; | ||
import { ClusterEnvironment } from '../../../types/provision'; | ||
|
||
export interface ControlledEnvironmentSelectProps<T extends FieldValues> | ||
extends UseControllerProps<T> { | ||
label: string; | ||
required?: boolean; | ||
control: Control<T>; | ||
options: ClusterEnvironment[]; | ||
onAddNewEnvironment: () => void; | ||
helperText?: string; | ||
onErrorText?: string; | ||
} | ||
|
||
function ControlledEnvironmentSelect<T extends FieldValues>({ | ||
label, | ||
name, | ||
required, | ||
rules, | ||
options, | ||
onAddNewEnvironment, | ||
...rest | ||
}: ControlledEnvironmentSelectProps<T>) { | ||
return ( | ||
<Controller | ||
name={name} | ||
rules={rules} | ||
{...rest} | ||
render={({ field, fieldState: { error } }) => ( | ||
<EnvironmentSelectWithRef | ||
{...field} | ||
inputRef={field.ref} | ||
fullWidth | ||
label={label} | ||
error={!!error} | ||
required={required} | ||
options={options} | ||
helperText={error ? rest.onErrorText : rest.helperText} | ||
onAddNewEnvironment={onAddNewEnvironment} | ||
/> | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
export default ControlledEnvironmentSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { Control, Controller, UseControllerProps, FieldValues } from 'react-hook-form'; | ||
|
||
import { TagSelectWithRef } from '../../select/'; | ||
|
||
export interface ControlledTagSelectProps<T extends FieldValues> extends UseControllerProps<T> { | ||
label: string; | ||
required?: boolean; | ||
control: Control<T>; | ||
options: readonly string[]; | ||
helperText?: string; | ||
onErrorText?: string; | ||
} | ||
|
||
function ControlledTagSelect<T extends FieldValues>({ | ||
label, | ||
name, | ||
required, | ||
rules, | ||
options, | ||
...rest | ||
}: ControlledTagSelectProps<T>) { | ||
return ( | ||
<Controller | ||
name={name} | ||
rules={rules} | ||
{...rest} | ||
render={({ field, fieldState: { error } }) => ( | ||
<TagSelectWithRef | ||
{...field} | ||
inputRef={field.ref} | ||
fullWidth | ||
label={label} | ||
error={!!error} | ||
required={required} | ||
options={options} | ||
helperText={error ? rest.onErrorText : rest.helperText} | ||
/> | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
export default ControlledTagSelect; |
38 changes: 38 additions & 0 deletions
38
components/controlledFields/tagSelect/tagSelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import { TAG_COLOR_OPTIONS, TagColor } from '../../tag'; | ||
|
||
import ControlledTagSelect from './index'; | ||
|
||
const meta: Meta<typeof ControlledTagSelect> = { | ||
component: ControlledTagSelect, | ||
}; | ||
|
||
export default meta; | ||
|
||
const ControlledTagSelectWithHooks = () => { | ||
const { | ||
control, | ||
formState: { errors }, | ||
} = useForm<{ labelColor: TagColor }>({ defaultValues: { labelColor: 'grey' }, mode: 'onBlur' }); | ||
|
||
return ( | ||
<ControlledTagSelect | ||
control={control} | ||
rules={{ | ||
required: 'label color is required', | ||
}} | ||
name="labelColor" | ||
label="Label color" | ||
required | ||
onErrorText={errors.labelColor?.message} | ||
options={TAG_COLOR_OPTIONS} | ||
/> | ||
); | ||
}; | ||
|
||
export const Default: StoryObj<typeof ControlledTagSelect> = { | ||
render: () => <ControlledTagSelectWithHooks />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import ControlledTextArea from './index'; | ||
|
||
const meta: Meta<typeof ControlledTextArea> = { | ||
component: ControlledTextArea, | ||
}; | ||
|
||
export default meta; | ||
|
||
const ControlledTextAreaWithHooks = () => { | ||
const { | ||
control, | ||
formState: { errors }, | ||
} = useForm({ defaultValues: { description: 'test' }, mode: 'onBlur' }); | ||
|
||
return ( | ||
<ControlledTextArea | ||
control={control} | ||
rules={{ | ||
required: 'Description is required', | ||
maxLength: { | ||
value: 280, | ||
message: 'Max 280 characters are permitted', | ||
}, | ||
}} | ||
label="Description" | ||
name="description" | ||
required | ||
onErrorText={errors.description?.message} | ||
/> | ||
); | ||
}; | ||
|
||
export const Default: StoryObj<typeof ControlledTextArea> = { | ||
render: () => <ControlledTextAreaWithHooks />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { Control, Controller, FieldValues, UseControllerProps } from 'react-hook-form'; | ||
|
||
import TextAreaWithRef from '../../textArea/'; | ||
|
||
export interface ControlledTextAreaProps<T extends FieldValues> extends UseControllerProps<T> { | ||
label: string; | ||
required?: boolean; | ||
control: Control<T>; | ||
helperText?: string; | ||
onErrorText?: string; | ||
} | ||
|
||
function ControlledTextArea<T extends FieldValues>({ | ||
label, | ||
...props | ||
}: ControlledTextAreaProps<T>) { | ||
return ( | ||
<Controller | ||
{...props} | ||
render={({ field, fieldState: { error } }) => ( | ||
<TextAreaWithRef | ||
{...field} | ||
required={props.required} | ||
label={label} | ||
error={!!error} | ||
helperText={error ? props.onErrorText : props.helperText} | ||
/> | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
export default ControlledTextArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
components/createEnvironmentMenu/createEnvironmentMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { CreateEnvironmentMenu } from '.'; | ||
|
||
const meta: Meta<typeof CreateEnvironmentMenu> = { | ||
component: CreateEnvironmentMenu, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof CreateEnvironmentMenu> = { | ||
args: { | ||
previouslyCreatedEnvironments: [ | ||
{ environmentName: 'development', labelColor: 'dark-sky-blue' }, | ||
], | ||
}, | ||
}; |
Oops, something went wrong.