Skip to content

Commit

Permalink
add types
Browse files Browse the repository at this point in the history
  • Loading branch information
sakibh committed Jun 28, 2022
1 parent 9667acb commit 1ca6d69
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
19 changes: 11 additions & 8 deletions protocol-designer/src/components/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { colors } from '../swatchColors'
import styles from './ColorPicker.css'

interface ColorPickerProps {
liquidId: string
value: string
onChange: (hex: ColorResult['hex']) => void
}

export function ColorPicker(props: ColorPickerProps): JSX.Element {
const [showColorPicker, setShowColorPicker] = React.useState<boolean>(false)
const [currentColor, setCurrentColor] = React.useState<ColorResult['hex']>(
'#000'
)

React.useEffect(() => {
console.log(props.value)
}, [props.value])

return (
<div>
<div
Expand All @@ -22,7 +25,7 @@ export function ColorPicker(props: ColorPickerProps): JSX.Element {
<div
className={styles.color}
style={{
backgroundColor: currentColor,
backgroundColor: props.value,
}}
/>
</div>
Expand All @@ -34,9 +37,9 @@ export function ColorPicker(props: ColorPickerProps): JSX.Element {
/>
<TwitterPicker
colors={colors}
color={currentColor}
onChange={color => {
setCurrentColor(color.hex)
color={props.value}
onChange={(color, event) => {
props.onChange(color.hex)
setShowColorPicker(showColorPicker => !showColorPicker)
}}
triangle="top-left"
Expand Down
14 changes: 13 additions & 1 deletion protocol-designer/src/components/LiquidsPage/LiquidEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import formStyles from '../forms/forms.css'

import { LiquidGroup } from '../../labware-ingred/types'
import { ColorPicker } from '../ColorPicker'
import { ColorResult } from 'react-color'

type Props = LiquidGroup & {
canDelete: boolean
Expand All @@ -25,6 +26,7 @@ type Props = LiquidGroup & {

interface LiquidEditFormValues {
name: string
displayColor: string
description?: string | null
serialize?: boolean
[key: string]: unknown
Expand All @@ -38,6 +40,7 @@ export const liquidEditFormSchema: Yup.Schema<
name: i18n.t('form.liquid_edit.name'),
})
),
displayColor: Yup.string(),
description: Yup.string(),
serialize: Yup.boolean(),
})
Expand All @@ -47,17 +50,23 @@ export function LiquidEditForm(props: Props): JSX.Element {

const initialValues: LiquidEditFormValues = {
name: props.name || '',
displayColor: props.displayColor || '',
description: props.description || '',
serialize: props.serialize || false,
}

const [currentColor, setCurrentColor] = React.useState<ColorResult['hex']>(
props.displayColor || '#000'
)

return (
<Formik
initialValues={initialValues}
validationSchema={liquidEditFormSchema}
onSubmit={(values: LiquidEditFormValues) => {
saveForm({
name: values.name,
displayColor: currentColor,
description: values.description || null,
serialize: values.serialize || false,
})
Expand Down Expand Up @@ -103,7 +112,10 @@ export function LiquidEditForm(props: Props): JSX.Element {
/>
</FormGroup>
<FormGroup label={'Liquid'} className={formStyles.column_1_3}>
<ColorPicker liquidId={'1'} />
<ColorPicker
value={currentColor}
onChange={setCurrentColor}
/>
</FormGroup>
</div>
</section>
Expand Down
2 changes: 2 additions & 0 deletions protocol-designer/src/components/LiquidsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function mapStateToProps(state: BaseState): SP {
name: selectedIngredFields.name,
// @ts-expect-error(sa, 2021-6-22): description might not exist
description: selectedIngredFields.description,
// @ts-expect-error(sh, 2022-6-28): displayColor might not exist
displayColor: selectedIngredFields.displayColor,
// @ts-expect-error(sa, 2021-6-22): serialize might not exist
serialize: selectedIngredFields.serialize,
}
Expand Down
2 changes: 2 additions & 0 deletions protocol-designer/src/labware-ingred/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export interface WellContentsByLabware {
export type OrderedLiquids = Array<{
ingredientId: string
name: string | null | undefined
displayColor: string
}>
// TODO: Ian 2018-10-15 audit & rename these confusing types
export interface LiquidGroup {
name: string | null | undefined
description: string | null | undefined
displayColor: string
serialize: boolean
}
export type IngredInputs = LiquidGroup & {
Expand Down

0 comments on commit 1ca6d69

Please sign in to comment.