-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): heater-shaker step form tools (#16342)
closes AUTH-811
- Loading branch information
Showing
11 changed files
with
497 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { css } from 'styled-components' | ||
import { | ||
ALIGN_CENTER, | ||
Btn, | ||
COLORS, | ||
Flex, | ||
Icon, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
interface ToggleProps { | ||
isSelected: boolean | ||
onClick: () => void | ||
label: string | ||
disabled?: boolean | ||
} | ||
export function Toggle(props: ToggleProps): JSX.Element { | ||
const { isSelected, onClick, label, disabled = false } = props | ||
return ( | ||
<Flex gridGap={SPACING.spacing8} alignItems={ALIGN_CENTER}> | ||
<StyledText desktopStyle="bodyDefaultRegular" color={COLORS.grey60}> | ||
{label} | ||
</StyledText> | ||
<Btn | ||
role="switch" | ||
size="2rem" | ||
css={isSelected ? TOGGLE_ENABLED_STYLES : TOGGLE_DISABLED_STYLES} | ||
onClick={disabled ? undefined : onClick} | ||
> | ||
<Icon | ||
name={isSelected ? 'ot-toggle-input-on' : 'ot-toggle-input-off'} | ||
size="1rem" | ||
/> | ||
</Btn> | ||
</Flex> | ||
) | ||
} | ||
|
||
const TOGGLE_DISABLED_STYLES = css` | ||
color: ${COLORS.grey50}; | ||
&:hover { | ||
color: ${COLORS.grey55}; | ||
} | ||
&:focus-visible { | ||
box-shadow: 0 0 0 3px ${COLORS.yellow50}; | ||
} | ||
&:disabled { | ||
color: ${COLORS.grey30}; | ||
} | ||
` | ||
|
||
const TOGGLE_ENABLED_STYLES = css` | ||
color: ${COLORS.blue50}; | ||
&:hover { | ||
color: ${COLORS.blue55}; | ||
} | ||
&:focus-visible { | ||
box-shadow: 0 0 0 3px ${COLORS.yellow50}; | ||
} | ||
&:disabled { | ||
color: ${COLORS.grey30}; | ||
} | ||
` |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './constants' | ||
export * from './Toggle' |
52 changes: 52 additions & 0 deletions
52
protocol-designer/src/molecules/CheckboxExpandStepFormField/index.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,52 @@ | ||
import { | ||
ALIGN_CENTER, | ||
Btn, | ||
COLORS, | ||
Check, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
JUSTIFY_SPACE_BETWEEN, | ||
ListItem, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
interface CheckboxExpandStepFormFieldProps { | ||
title: string | ||
checkboxUpdateValue: (value: unknown) => void | ||
checkboxValue: unknown | ||
isChecked: boolean | ||
children: React.ReactNode | ||
} | ||
export function CheckboxExpandStepFormField( | ||
props: CheckboxExpandStepFormFieldProps | ||
): JSX.Element { | ||
const { | ||
checkboxUpdateValue, | ||
checkboxValue, | ||
children, | ||
isChecked, | ||
title, | ||
} = props | ||
return ( | ||
<ListItem type="noActive"> | ||
<Flex | ||
padding={SPACING.spacing12} | ||
width="100%" | ||
flexDirection={DIRECTION_COLUMN} | ||
> | ||
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} alignItems={ALIGN_CENTER}> | ||
<StyledText desktopStyle="bodyDefaultRegular">{title}</StyledText> | ||
<Btn | ||
onClick={() => { | ||
checkboxUpdateValue(!checkboxValue) | ||
}} | ||
> | ||
<Check color={COLORS.blue50} isChecked={isChecked} /> | ||
</Btn> | ||
</Flex> | ||
{children} | ||
</Flex> | ||
</ListItem> | ||
) | ||
} |
81 changes: 81 additions & 0 deletions
81
protocol-designer/src/molecules/InputStepFormField/index.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,81 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
Icon, | ||
InputField, | ||
SPACING, | ||
StyledText, | ||
Tooltip, | ||
useHoverTooltip, | ||
} from '@opentrons/components' | ||
import { getFieldDefaultTooltip } from '../../components/StepEditForm/utils' | ||
|
||
import type { FieldProps } from '../../components/StepEditForm/types' | ||
|
||
interface InputStepFormFieldProps extends FieldProps { | ||
title: string | ||
units: string | ||
padding?: string | ||
showTooltip?: boolean | ||
} | ||
|
||
export function InputStepFormField( | ||
props: InputStepFormFieldProps | ||
): JSX.Element { | ||
const { | ||
errorToShow, | ||
onFieldBlur, | ||
onFieldFocus, | ||
updateValue, | ||
value, | ||
name, | ||
title, | ||
units, | ||
showTooltip = true, | ||
padding = SPACING.spacing16, | ||
...otherProps | ||
} = props | ||
const { t } = useTranslation(['tooltip', 'application']) | ||
const [targetProps, tooltipProps] = useHoverTooltip() | ||
|
||
return ( | ||
<Flex flexDirection={DIRECTION_COLUMN} padding={padding}> | ||
{title !== null ? ( | ||
<Flex gridGap={SPACING.spacing8} paddingBottom={SPACING.spacing8}> | ||
<StyledText desktopStyle="captionRegular" color={COLORS.grey60}> | ||
{title} | ||
</StyledText> | ||
{showTooltip ? ( | ||
<> | ||
<Flex {...targetProps}> | ||
<Icon | ||
name="information" | ||
size={SPACING.spacing12} | ||
color={COLORS.grey60} | ||
data-testid="information_icon" | ||
/> | ||
</Flex> | ||
<Tooltip tooltipProps={tooltipProps}> | ||
{getFieldDefaultTooltip(name, t)} | ||
</Tooltip> | ||
</> | ||
) : null} | ||
</Flex> | ||
) : null} | ||
<InputField | ||
{...otherProps} | ||
name={name} | ||
error={errorToShow} | ||
onBlur={onFieldBlur} | ||
onFocus={onFieldFocus} | ||
onChange={e => { | ||
updateValue(e.currentTarget.value) | ||
}} | ||
value={value ? String(value) : null} | ||
units={units} | ||
/> | ||
</Flex> | ||
) | ||
} |
68 changes: 68 additions & 0 deletions
68
protocol-designer/src/molecules/ToggleExpandStepFormField/index.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,68 @@ | ||
import { | ||
ALIGN_CENTER, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
JUSTIFY_SPACE_BETWEEN, | ||
ListItem, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
import { Toggle } from '../../atoms' | ||
import { InputStepFormField } from '../InputStepFormField' | ||
import type { FieldProps } from '../../pages/Designer/ProtocolSteps/StepForm/types' | ||
|
||
interface ToggleExpandStepFormFieldProps extends FieldProps { | ||
title: string | ||
fieldTitle: string | ||
isSelected: boolean | ||
units: string | ||
onLabel: string | ||
offLabel: string | ||
toggleUpdateValue: (value: unknown) => void | ||
toggleValue: unknown | ||
} | ||
export function ToggleExpandStepFormField( | ||
props: ToggleExpandStepFormFieldProps | ||
): JSX.Element { | ||
const { | ||
title, | ||
isSelected, | ||
onLabel, | ||
offLabel, | ||
fieldTitle, | ||
units, | ||
toggleUpdateValue, | ||
toggleValue, | ||
...restProps | ||
} = props | ||
|
||
return ( | ||
<ListItem type="noActive"> | ||
<Flex | ||
padding={SPACING.spacing12} | ||
width="100%" | ||
flexDirection={DIRECTION_COLUMN} | ||
> | ||
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} alignItems={ALIGN_CENTER}> | ||
<StyledText desktopStyle="bodyDefaultRegular">{title}</StyledText> | ||
<Toggle | ||
onClick={() => { | ||
toggleUpdateValue(!toggleValue) | ||
}} | ||
label={isSelected ? onLabel : offLabel} | ||
isSelected={isSelected} | ||
/> | ||
</Flex> | ||
{isSelected ? ( | ||
<InputStepFormField | ||
{...restProps} | ||
padding="0" | ||
showTooltip={false} | ||
title={fieldTitle} | ||
units={units} | ||
/> | ||
) : null} | ||
</Flex> | ||
</ListItem> | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
protocol-designer/src/molecules/ToggleStepFormField/index.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,72 @@ | ||
import { | ||
ALIGN_CENTER, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
JUSTIFY_SPACE_BETWEEN, | ||
ListItem, | ||
SPACING, | ||
StyledText, | ||
TOOLTIP_BOTTOM, | ||
Tooltip, | ||
useHoverTooltip, | ||
} from '@opentrons/components' | ||
import { Toggle } from '../../atoms' | ||
|
||
interface ToggleStepFormFieldProps { | ||
title: string | ||
isSelected: boolean | ||
onLabel: string | ||
offLabel: string | ||
toggleUpdateValue: (value: unknown) => void | ||
toggleValue: unknown | ||
tooltipContent: string | null | ||
isDisabled: boolean | ||
} | ||
export function ToggleStepFormField( | ||
props: ToggleStepFormFieldProps | ||
): JSX.Element { | ||
const { | ||
title, | ||
isSelected, | ||
onLabel, | ||
offLabel, | ||
toggleUpdateValue, | ||
toggleValue, | ||
tooltipContent, | ||
isDisabled, | ||
} = props | ||
const [targetProps, tooltipProps] = useHoverTooltip({ | ||
placement: TOOLTIP_BOTTOM, | ||
}) | ||
|
||
return ( | ||
<> | ||
<ListItem type="noActive"> | ||
<Flex | ||
padding={SPACING.spacing12} | ||
width="100%" | ||
flexDirection={DIRECTION_COLUMN} | ||
> | ||
<Flex | ||
justifyContent={JUSTIFY_SPACE_BETWEEN} | ||
alignItems={ALIGN_CENTER} | ||
{...targetProps} | ||
> | ||
<StyledText desktopStyle="bodyDefaultRegular">{title}</StyledText> | ||
<Toggle | ||
disabled={isDisabled} | ||
onClick={() => { | ||
toggleUpdateValue(!toggleValue) | ||
}} | ||
label={isSelected ? onLabel : offLabel} | ||
isSelected={isSelected} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</ListItem> | ||
{tooltipContent != null ? ( | ||
<Tooltip tooltipProps={tooltipProps}>{tooltipContent}</Tooltip> | ||
) : null} | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export * from './CheckboxExpandStepFormField' | ||
export * from './CheckboxStepFormField' | ||
export * from './DropdownStepFormField' | ||
export * from './InputStepFormField' | ||
export * from './SettingsIcon' | ||
export * from './ToggleExpandStepFormField' | ||
export * from './ToggleStepFormField' |
Oops, something went wrong.