Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

CheckButton #1869

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/renderer/components/uielements/button/CheckButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react'

import { Story, Meta } from '@storybook/react'
import * as FP from 'fp-ts/lib/function'

import { CheckButton } from './CheckButton'

type Args = {
label: string
disabled: boolean
isChecked: boolean
onClicked: FP.Lazy<void>
}

const Template: Story<Args> = ({ label, disabled, isChecked, onClicked }) => {
return (
<CheckButton disabled={disabled} isChecked={isChecked} clickHandler={onClicked}>
{label}
</CheckButton>
)
}

export const Default = Template.bind({})

Default.storyName = 'default'

const meta: Meta<Args> = {
component: CheckButton,
title: 'Components/button/CheckButton',
argTypes: {
label: {
name: 'Label',
control: {
type: 'text'
},
defaultValue: 'Label'
},
disabled: {
name: 'disabled',
control: {
type: 'boolean'
},
defaultValue: false
},
isChecked: {
name: 'isChecked',
control: {
type: 'boolean'
},
defaultValue: false
},
onClicked: {
action: 'onClicked'
}
},
decorators: [
(S: Story) => (
<div
style={{
display: 'flex',
flexDirection: 'row'
}}>
<S />
</div>
)
]
}

export default meta
34 changes: 34 additions & 0 deletions src/renderer/components/uielements/button/CheckButton.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as AIcon from '@ant-design/icons'
import * as A from 'antd'
import styled from 'styled-components'

import { Button as ButtonUI } from './Button'

export const ContentWrapper = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
`

export const CheckCircleOutlined = styled(AIcon.CheckCircleOutlined)<{ checked: boolean }>`
padding-right: 5px;
// Add some transparency if checked
opacity: ${(props) => (props.checked ? '1' : '0.7')};

// hide arrow if not checked
svg path:nth-child(1) {
opacity: ${(props) => (props.checked ? '1' : '0')};
}
`

type ButtonProps = { checked: boolean } & A.ButtonProps

export const Button = styled(ButtonUI).attrs({
typevalue: 'transparent',
type: 'text'
})<ButtonProps>`
box-shadow: none;
padding: 0px;
min-width: auto !important;
margin-right: 5px;
`
31 changes: 31 additions & 0 deletions src/renderer/components/uielements/button/CheckButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useState, useCallback } from 'react'

import * as FP from 'fp-ts/function'

import * as Styled from './CheckButton.styles'

export type Props = {
clickHandler?: FP.Lazy<void>
disabled?: boolean
isChecked?: boolean
}

export const CheckButton: React.FC<Props> = (props): JSX.Element => {
const { clickHandler = FP.constVoid, disabled, isChecked, children } = props

const [checked, setChecked] = useState(!!isChecked)

const onClickHandler = useCallback(() => {
setChecked(() => !checked)
clickHandler && clickHandler()
}, [checked, clickHandler])

return (
<Styled.Button onClick={onClickHandler} disabled={disabled} checked={checked}>
<Styled.ContentWrapper>
<Styled.CheckCircleOutlined checked={checked} />
{children}
</Styled.ContentWrapper>
</Styled.Button>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'

import { Story, Meta } from '@storybook/react'
import * as FP from 'fp-ts/lib/function'

import { RefreshButton } from './RefreshButton'

type Args = {
label: string
disabled: boolean
onClicked: FP.Lazy<void>
}

const Template: Story<Args> = ({ label, disabled, onClicked }) => {
return <RefreshButton disabled={disabled} clickHandler={onClicked} label={label} />
}

export const Default = Template.bind({})

Default.storyName = 'default'

const meta: Meta<Args> = {
component: RefreshButton,
title: 'Components/button/RefreshButton',
argTypes: {
label: {
name: 'Label',
control: {
type: 'text'
},
defaultValue: 'Label'
},
disabled: {
name: 'disabled',
control: {
type: 'boolean'
},
defaultValue: false
},
onClicked: {
action: 'onClicked'
}
},
decorators: [
(S: Story) => (
<div
style={{
display: 'flex',
flexDirection: 'row'
}}>
<S />
</div>
)
]
}

export default meta