Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkbox component closes #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions packages/react/core/components/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { CheckboxProps } from '@blank/types'
import React from 'react'

const Checkbox: React.FC<CheckboxProps> = ({
size = 'medium',
direction,
label,
checked,
onChange,
disabled = false,
}) => {
const handleClick = () => {
if (disabled)
return
if (onChange) {
onChange(!checked)
}
}

return (
<div
className={`blank checkbox ${size} ${direction} ${disabled ? 'disabled' : ''}`}
onClick={handleClick}
tabIndex={disabled ? -1 : 0}
role="checkbox"
aria-checked={checked}
aria-disabled={disabled}
>
<input
type="checkbox"
className={`blank checkbox__input ${size}`}
checked={checked}
onChange={e => e.stopPropagation()}
aria-label={label}
disabled={disabled}
/>
<span className={`blank checkbox__label ${size} ${disabled ? 'disabled' : ''}`}>
{label}
</span>
</div>
)
}

export default Checkbox
1 change: 1 addition & 0 deletions packages/react/core/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export { default as Badge } from './badge'
export { default as BadgeGroup } from './badgeGroup'
export { default as Button } from './button'
export { default as ButtonGroup } from './buttonGroup'
export { default as Checkbox } from './checkbox'
export { Tabs, TabsContent, TabsList, TabsTrigger } from './tabs'
export { default as Toggle } from './toggle'
65 changes: 65 additions & 0 deletions packages/styles/core/components/checkbox.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.blank
&.checkbox
display flex
align-items center
cursor pointer
user-select none
width max-content;

&.disabled
cursor not-allowed

&.left
flex-direction row-reverse

&.right
flex-direction row

&__input
appearance none
border 1px solid $AlphaBlack10
border-radius 4px
background-color $BaseWhite
cursor pointer
transition all 0.1s ease-in-out
position relative

&.small
width 20px
height 20px

&.medium
width 24px
height 24px

&:checked
background-color $Info500
border-color $Info500

&::after
content '✔'
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
font-size 14px
color $BaseWhite

&:disabled
background-color $AlphaBlack5
border-color $AlphaBlack10
cursor not-allowed

&__label
margin 0 8px
color inherit
text-decoration none

&.small
Caption1(500)

&.medium
Body2(500)

&.disabled
color $AlphaBlack30
2 changes: 2 additions & 0 deletions packages/styles/core/components/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
@import 'avatar.styl'
@import 'avatarGroup.styl'
@import 'tabs.styl'
@import 'checkbox.styl'

56 changes: 56 additions & 0 deletions packages/vue/core/components/checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script setup lang="ts">
import type { CheckboxProps } from '@blank/types'
import { ref, watch } from 'vue'

const props = withDefaults(defineProps<CheckboxProps>(), {
size: 'medium',
direction: 'left',
label: '',
checked: false,
disabled: false,
})

const internalChecked = ref(props.checked)

watch(() => props.checked, (newChecked) => {
internalChecked.value = newChecked
})

function handleClick() {
if (props.disabled)
return

internalChecked.value = !internalChecked.value

if (props.onChange) {
props.onChange(internalChecked.value)
}
}
</script>

<template>
<div
class="blank checkbox"
:class="[props.size, props.direction, { disabled: props.disabled }] "
tabindex="0"
role="checkbox"
:aria-checked="internalChecked"
:aria-disabled="props.disabled"
@click="handleClick"
>
<input
v-model="internalChecked"
type="checkbox"
class="blank checkbox__input"
:class="props.size"
:aria-label="props.label"
:disabled="props.disabled"
>
<span
class="blank checkbox__label"
:class="[props.size, { disabled: props.disabled }] "
>
{{ props.label }}
</span>
</div>
</template>
1 change: 1 addition & 0 deletions packages/vue/core/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as Badge } from './badge.vue'
export { default as BadgeGroup } from './badgeGroup.vue'
export { default as Button } from './button.vue'
export { default as ButtonGroup } from './buttonGroup.vue'
export { default as Checkbox } from './checkbox.vue'
export { default as Input } from './input/index.vue'
export { default as Radio } from './radio.vue'
export { default as RadioGroup } from './radioGroup.vue'
Expand Down
21 changes: 19 additions & 2 deletions playground/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Avatar, AvatarGroup, Badge, BadgeGroup, Button, Icon, Tabs, TabsContent, TabsList, TabsTrigger, Toggle } from '@blank/react'
import { Avatar, AvatarGroup, Badge, BadgeGroup, Button, Checkbox, Icon, Tabs, TabsContent, TabsList, TabsTrigger, Toggle } from '@blank/react'
import { useState } from 'react'

function App() {
const badges = [{ label: 'test', backgroundColor: 'grey', color: 'white' }, { label: 'test', backgroundColor: 'transparent', color: 'white', icon: 'remix:command-fill' }]

const [check, useCheck] = useState(false)
return (
<div>
<Button size="small">
Expand Down Expand Up @@ -113,6 +114,22 @@ function App() {
<TabsContent value={2}>Content for Tab 3</TabsContent>
</Tabs>
</div>
<Checkbox
size="small"
direction="right"
label="Chek Me!"
checked={check}
onChange={() => useCheck(!check)}
disabled={false}
/>
<Checkbox
size="medium"
direction="left"
label="Chek Me!"
checked={check}
onChange={() => useCheck(!check)}
disabled={false}
/>

</div>
)
Expand Down
24 changes: 22 additions & 2 deletions playground/vue/src/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Avatar, AvatarGroup, Badge, BadgeGroup, Button, ButtonGroup, Container, Icon, Input, Radio, RadioGroup, Tabs, TabsContent, TabsList, TabsTrigger, Toggle } from '@blank/vue'
import { Avatar, AvatarGroup, Badge, BadgeGroup, Button, ButtonGroup, Checkbox, Container, Icon, Input, Radio, RadioGroup, Tabs, TabsContent, TabsList, TabsTrigger, Toggle } from '@blank/vue'
import { ref, watch } from 'vue'

const badges = [{ label: 'test', backgroundColor: 'grey', color: 'white' }, { label: 'test', backgroundColor: 'transparent', color: 'white', icon: 'remix:command-fill' }]
Expand All @@ -13,6 +13,11 @@ watch(selectedRadio, (newValue) => {
console.log(`Seçilen değer INDEX: ${newValue}`)
}
})
const check = ref(false)

function useCheck(newValue: boolean) {
check.value = newValue
}
</script>

<template>
Expand Down Expand Up @@ -134,7 +139,22 @@ watch(selectedRadio, (newValue) => {
test
</Badge>
<BadgeGroup variant="primary" :badges="badges" @click="handleClick" />

<Checkbox
size="small"
direction="left"
label="Check Me!"
:checked="check"
:disabled="false"
@on-change="useCheck"
/>
<Checkbox
size="medium"
direction="left"
label="Check Me!"
:checked="check"
:disabled="false"
@on-change="useCheck"
/>
<div>
<Avatar
src="https://files.kick.com/images/user/27079011/profile_image/conversion/6e002a5e-8fd1-461c-8c7a-79fe6b71cdff-medium.webp"
Expand Down
9 changes: 9 additions & 0 deletions shared/types/src/components/checkbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface CheckboxProps {
size?: 'small' | 'medium'
direction?: 'left' | 'right'
label?: string
checked?: boolean
onChange?: (checked: boolean) => void
disabled?: boolean
}
export type { CheckboxProps }
1 change: 1 addition & 0 deletions shared/types/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './badge'
export * from './badgeGroups'
export * from './button'
export * from './buttonGroups'
export * from './checkbox'
export * from './input'
export * from './radio'
export * from './radioGroup'
Expand Down