-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): Add InterventionInfo: Move component (#15387)
Adds the Move component, used in InterventionModal, to the app.
- Loading branch information
1 parent
96c5e64
commit 831195c
Showing
4 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/src/molecules/InterventionModal/InterventionStep/Move.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,89 @@ | ||
import { ICON_DATA_BY_NAME } from '@opentrons/components' | ||
|
||
import { Move } from './Move' | ||
|
||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
const meta: Meta<typeof Move> = { | ||
title: 'App/Organisms/InterventionModal/InterventionStep/Move', | ||
component: Move, | ||
argTypes: { | ||
type: { | ||
control: { | ||
type: 'select', | ||
options: ['move', 'refill', 'select'], | ||
}, | ||
}, | ||
labwareName: { | ||
control: 'text', | ||
}, | ||
currentLocationProps: { | ||
control: { | ||
type: 'object', | ||
}, | ||
slotName: { | ||
control: 'text', | ||
}, | ||
iconName: { | ||
control: { | ||
type: 'select', | ||
options: Object.keys(ICON_DATA_BY_NAME), | ||
}, | ||
}, | ||
}, | ||
newLocationProps: { | ||
control: { | ||
type: 'object', | ||
}, | ||
slotName: { | ||
control: 'text', | ||
}, | ||
iconName: { | ||
control: { | ||
type: 'select', | ||
options: Object.keys(ICON_DATA_BY_NAME), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Move> | ||
|
||
export const MoveBetweenSlots: Story = { | ||
args: { | ||
type: 'move', | ||
labwareName: 'Plate', | ||
currentLocationProps: { | ||
slotName: 'A1', | ||
}, | ||
newLocationProps: { | ||
slotName: 'B2', | ||
}, | ||
}, | ||
} | ||
|
||
export const Refill: Story = { | ||
args: { | ||
type: 'refill', | ||
labwareName: 'Tip Rack', | ||
currentLocationProps: { | ||
slotName: 'A1', | ||
}, | ||
}, | ||
} | ||
|
||
export const Select: Story = { | ||
args: { | ||
type: 'select', | ||
labwareName: 'Well', | ||
currentLocationProps: { | ||
slotName: 'A1', | ||
}, | ||
newLocationProps: { | ||
slotName: 'B1', | ||
}, | ||
}, | ||
} |
99 changes: 99 additions & 0 deletions
99
app/src/molecules/InterventionModal/InterventionStep/Move.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,99 @@ | ||
import * as React from 'react' | ||
import { css } from 'styled-components' | ||
|
||
import { | ||
LocationIcon, | ||
Flex, | ||
Icon, | ||
COLORS, | ||
BORDERS, | ||
SPACING, | ||
DIRECTION_COLUMN, | ||
StyledText, | ||
ALIGN_CENTER, | ||
} from '@opentrons/components' | ||
|
||
import type { LocationIconProps } from '@opentrons/components' | ||
|
||
export interface MoveProps { | ||
type: 'move' | 'refill' | 'select' | ||
labwareName: string | ||
currentLocationProps: LocationIconProps | ||
newLocationProps?: LocationIconProps | ||
} | ||
|
||
export function Move(props: MoveProps): JSX.Element { | ||
const content = buildContent(props) | ||
|
||
return ( | ||
<Flex css={CARD_STYLE}> | ||
<StyledText as="pBold">{props.labwareName}</StyledText> | ||
{content} | ||
</Flex> | ||
) | ||
} | ||
|
||
const buildContent = (props: MoveProps): JSX.Element => { | ||
switch (props.type) { | ||
case 'move': | ||
return buildMove(props) | ||
case 'refill': | ||
return buildRefill(props) | ||
case 'select': | ||
return buildSelect(props) | ||
} | ||
} | ||
|
||
const buildMove = (props: MoveProps): JSX.Element => { | ||
const { currentLocationProps, newLocationProps } = props | ||
|
||
if (newLocationProps != null) { | ||
return ( | ||
<Flex gridGap={SPACING.spacing8} alignItems={ALIGN_CENTER}> | ||
<LocationIcon {...currentLocationProps} /> | ||
<Icon name="arrow-right" css={ICON_STYLE} /> | ||
<LocationIcon {...newLocationProps} /> | ||
</Flex> | ||
) | ||
} else { | ||
return buildRefill(props) | ||
} | ||
} | ||
|
||
const buildRefill = ({ currentLocationProps }: MoveProps): JSX.Element => { | ||
return ( | ||
<Flex gridGap={SPACING.spacing8}> | ||
<LocationIcon {...currentLocationProps} /> | ||
</Flex> | ||
) | ||
} | ||
|
||
const buildSelect = (props: MoveProps): JSX.Element => { | ||
const { currentLocationProps, newLocationProps } = props | ||
|
||
if (newLocationProps != null) { | ||
return ( | ||
<Flex gridGap={SPACING.spacing8}> | ||
<LocationIcon {...currentLocationProps} /> | ||
<Icon name="colon" css={ICON_STYLE} /> | ||
<LocationIcon {...newLocationProps} /> | ||
</Flex> | ||
) | ||
} else { | ||
return buildRefill(props) | ||
} | ||
} | ||
|
||
const ICON_STYLE = css` | ||
width: ${SPACING.spacing40}; | ||
height: ${SPACING.spacing40}; | ||
` | ||
|
||
const CARD_STYLE = css` | ||
flex-direction: ${DIRECTION_COLUMN}; | ||
background-color: ${COLORS.grey35}; | ||
width: 26.75rem; | ||
padding: ${SPACING.spacing16}; | ||
grid-gap: ${SPACING.spacing8}; | ||
border-radius: ${BORDERS.borderRadius8}; | ||
` |
3 changes: 3 additions & 0 deletions
3
app/src/molecules/InterventionModal/InterventionStep/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,3 @@ | ||
export { Move } from './Move' | ||
|
||
export type { MoveProps } from './Move' |
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