Skip to content

Commit

Permalink
refactor: minor QueryItem Action refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeAstra committed Apr 24, 2024
1 parent 5065bdd commit 9df86b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 5 additions & 7 deletions src/components/data-entry/QueryItem/Action.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ type Story = StoryObj<typeof QueryItem.Action>
export const Primary: Story = {
args: {
text: 'Primary Action',
isPrimary: true,
isDisabled: false,
type: "primary"
},
}

export const Secondary: Story = {
args: {
text: 'Secondary Action',
isPrimary: false,
isDisabled: false,
type: "default"
},
}

export const Disabled: Story = {
args: {
text: 'Disabled Action',
isPrimary: true,
isDisabled: true,
type: "disabled"

},
}

export const OnClick: Story = {
args: {
text: 'On Click Action',
isPrimary: true,
type: "primary",
onClick: () => alert('You clicked the QueryItem.Action!')
},
}
19 changes: 12 additions & 7 deletions src/components/data-entry/QueryItem/Action.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { AddIcon, Button } from 'src/components'
import { AddIcon, Button, IButtonProps } from 'src/components'
import './query-item.css'

export interface IActionProps {
isPrimary?: boolean
isDisabled?: boolean
type?: 'disabled' | 'primary' | 'default'
text?: string
onClick?: () => void
}

export const Action = (props: IActionProps) => {
const buttonClassNames: string = props.isPrimary
? 'query-item query-item--action'
: 'query-item query-item--action query-item--secondary'
let buttonClassNames: string = 'query-item query-item--action'
if ((props.type ?? 'default') !== 'primary') buttonClassNames += ` query-item--secondary`
const baseProps: IButtonProps = {
className: buttonClassNames,
type: props.type === 'disabled' ? 'default' : 'primary',
disabled: props.type === 'disabled',
onClick: props.onClick,
}

return (
<>
<Button className={buttonClassNames} type={props.isPrimary ? 'primary' : 'default'} disabled={props.isDisabled} onClick={props.onClick}>
<Button {...baseProps}>
<AddIcon className="query-item__icon" />
<span>{props.text}</span>
</Button>
Expand Down

0 comments on commit 9df86b2

Please sign in to comment.