Skip to content

Commit

Permalink
feat: add disable clear button
Browse files Browse the repository at this point in the history
Signed-off-by: hxtree <[email protected]>
  • Loading branch information
hxtree committed Dec 22, 2023
1 parent 1a952a6 commit 2c7f378
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
25 changes: 12 additions & 13 deletions services/admin-client/src/components/DiceAnalyzer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,20 @@ export const DiceAnalyzer = (props: DiceAnalyzerProps) => {
</Grid>
<div>
<Button
color="secondary"
onClick={() => clear()}
// TODO clear should be disabled when already cleared
// disabled="true"
testId={`dice-analyzer-clear`}
ref={(ref: any) => analytics.set(ref, 'Clear')}>
Clear
color="secondary"
onClick={() => clear()}
disabled={data.length < 1}
testId={`dice-analyzer-clear`}
ref={(ref: any) => analytics.set(ref, 'Clear')}>
Clear
</Button>
<Button
color="primary"
loading={isLoading}
onClick={() => callApi()}
testId={`dice-analyzer-roll`}
ref={(ref: any) => analytics.set(ref, 'Roll')}>
Roll
color="primary"
loading={isLoading}
onClick={() => callApi()}
testId={`dice-analyzer-roll`}
ref={(ref: any) => analytics.set(ref, 'Roll')}>
Roll
</Button>
Expand Down
11 changes: 9 additions & 2 deletions services/design-system/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export type ButtonProps = {
selected?: boolean;
size?: keyof typeof ButtonSize;
href?: string; // TODO add support
disabled?: boolean;
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
testId?: string;
}

export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props: ButtonProps, ref) => {
const { testId, href, loading, color, children, variant, selected, size, onClick } = props;
const { disabled, testId, href, loading, color, children, variant, selected, size, onClick } = props;

const classNames: string[] = ['button'];

Expand Down Expand Up @@ -63,14 +64,20 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props: B
}

let onClickHandler;
if (onClick !== undefined) {
let isButtonDisabled = false;

if(disabled){
isButtonDisabled = true;
classNames.push(`button-disabled`)
} else if (onClick !== undefined) {
onClickHandler = onClick;
} else if(href){
onClickHandler = () => { window.location.href = href};
}

return (
<button
disabled={isButtonDisabled}
className={classNames.join(' ')}
onClick={ onClickHandler }
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
border: none;
margin: 8px;
box-shadow: none;

&.button-disabled {
opacity: 0.5;
border: 3px solid $color-white !important;
background-color: $color-gray !important;
color: $color-black !important;
cursor: not-allowed;
}
&.button-primary {
border: 3px solid $color-primary;
background-color: $color-primary;
Expand Down

0 comments on commit 2c7f378

Please sign in to comment.