@geckou/ui-react 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geckou/ui-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A set of reusable React UI components (forms) by Geckou",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import type { Option, CheckBoxStyleForEachStatus } from '../types'
3
+ import type { Option, SelectValue, CheckBoxStyleForEachStatus } from '../types'
4
4
  import { MESSAGES } from '@geckou/ui-core'
5
5
  import { useEffect, useRef, useState } from 'react'
6
6
  import { LabeledCheckbox } from './LabeledCheckbox'
@@ -10,8 +10,8 @@ import { COLOR } from '../constants'
10
10
  type Props = {
11
11
  name: string
12
12
  options: Option[]
13
- value?: string[]
14
- onChange?: (newValue: string[]) => void
13
+ value?: SelectValue[]
14
+ onChange?: (newValue: SelectValue[]) => void
15
15
  isDisabled?: boolean
16
16
  isRequired?: boolean
17
17
  cssStyle?: CheckBoxStyleForEachStatus
@@ -26,10 +26,10 @@ export function CheckBoxes({
26
26
  isRequired,
27
27
  cssStyle,
28
28
  }: Props) {
29
- const [checkedValues, setCheckedValues] = useState<string[]>(value ?? [])
29
+ const [checkedValues, setCheckedValues] = useState<SelectValue[]>(value ?? [])
30
30
  const [errorMessage, setErrorMessage] = useState('')
31
31
 
32
- const validateInput = (newValues: string[]) =>
32
+ const validateInput = (newValues: SelectValue[]) =>
33
33
  setErrorMessage(isRequired && newValues.length === 0 ? MESSAGES.required : '')
34
34
 
35
35
  const isFirstRender = useRef(true)
@@ -45,9 +45,9 @@ export function CheckBoxes({
45
45
  // eslint-disable-next-line react-hooks/exhaustive-deps -- Vue 版(@geckou/ui-vue)同様、外部からの値変更時のみ同期する
46
46
  }, [value])
47
47
 
48
- const toggleValue = (optionValue: string, checked: boolean) => {
48
+ const toggleValue = (optionValue: SelectValue, checked: boolean) => {
49
49
  const newValues = options
50
- .map((option) => String(option.value))
50
+ .map((option) => option.value)
51
51
  .filter((candidate) =>
52
52
  candidate === optionValue ? checked : checkedValues.includes(candidate),
53
53
  )
@@ -75,8 +75,8 @@ export function CheckBoxes({
75
75
  key={option.value}
76
76
  name={name}
77
77
  label={option.label}
78
- checked={checkedValues.includes(String(option.value))}
79
- onChange={(checked) => toggleValue(String(option.value), checked)}
78
+ checked={checkedValues.includes(option.value)}
79
+ onChange={(checked) => toggleValue(option.value, checked)}
80
80
  isDisabled={isDisabled}
81
81
  cssStyle={cssStyle}
82
82
  />