refactor: add a unified warning function

This commit is contained in:
unix
2020-03-25 02:03:17 +08:00
parent 03578c2b68
commit 269a2bfae5
10 changed files with 46 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import useTheme from '../styles/use-theme'
import withDefaults from '../utils/with-defaults'
import useCurrentState from '../utils/use-current-state'
import { FieldsetContext, FieldItem } from './fieldset-context'
import useWarning from '../utils/use-warning'
interface Props {
value: string
@@ -26,7 +27,7 @@ const FieldsetGroup: React.FC<React.PropsWithChildren<FieldsetGroupProps>> = Rea
const register = useCallback((newItem: FieldItem) => {
const hasItem = ref.current.find(item => item.value === newItem.value)
if (hasItem) {
console.error('[Fieldset Group]: The "value" of each "Fieldset" must be unique.')
useWarning('The "value" of each "Fieldset" must be unique.', 'Fieldset')
}
setItems([...ref.current, newItem])
}, [])

View File

@@ -6,6 +6,7 @@ import FieldsetFooter from './fieldset-footer'
import FieldsetGroup from './fieldset-group'
import { hasChild, pickChild } from '../utils/collections'
import { useFieldset } from './fieldset-context'
import useWarning from '../utils/use-warning'
interface Props {
value?: string
@@ -38,7 +39,7 @@ const Fieldset: React.FC<React.PropsWithChildren<FieldsetProps>> = React.memo(({
if (inGroup) {
if (!label) {
console.error('[Fieldset Group]: Props "label" is required when in a group.')
useWarning('Props "label" is required when in a group.', 'Fieldset Group')
}
if (!value || value === '') {
value = label