diff --git a/scripts/build-taro.mjs b/scripts/build-taro.mjs index ae4f270888..1500f00ae2 100644 --- a/scripts/build-taro.mjs +++ b/scripts/build-taro.mjs @@ -68,6 +68,7 @@ async function buildES(p) { [ 'src/packages/**/*.taro.{ts,tsx}', 'src/packages/**/types.ts', + 'src/packages/**/icon.tsx', 'src/packages/**/context.ts', 'src/packages/**/utils.ts', 'src/utils/**/*.{ts,tsx}', diff --git a/src/packages/checkbox/__test__/__snapshots__/checkbox.spec.tsx.snap b/src/packages/checkbox/__test__/__snapshots__/checkbox.spec.tsx.snap index 43eeb2ebe9..d8d689d5fd 100644 --- a/src/packages/checkbox/__test__/__snapshots__/checkbox.spec.tsx.snap +++ b/src/packages/checkbox/__test__/__snapshots__/checkbox.spec.tsx.snap @@ -5,19 +5,9 @@ exports[`should match snapshot 1`] = `
- - - +
diff --git a/src/packages/checkbox/__test__/checkbox.spec.tsx b/src/packages/checkbox/__test__/checkbox.spec.tsx index e453285673..ed68fcc713 100644 --- a/src/packages/checkbox/__test__/checkbox.spec.tsx +++ b/src/packages/checkbox/__test__/checkbox.spec.tsx @@ -75,7 +75,7 @@ test('should fireEvent correctly', () => { fireEvent.click(getByTestId('checkbox3')) fireEvent.click(getByTestId('checkbox1')) - const icons = container.querySelectorAll('.nut-checkbox-icon-checked') + const icons = container.querySelectorAll('.nut-checkbox-self-checked') expect(icons.length).toBe(1) expect(limit).toBeCalledWith('min') @@ -117,28 +117,26 @@ test('Render checkboxs by configure indeterminate', () => { const { container } = render( ) - expect( - container.querySelector('.nut-checkbox-icon-indeterminate') - ).toBeTruthy() + expect(container.querySelector('.nut-checkbox-self-disabled')).toBeTruthy() }) test('Render checkboxs by configure disabled', () => { const { container } = render( ) - expect(container.querySelector('.nut-checkbox-icon-disabled')).toBeTruthy() + expect( + container.querySelector('.nut-checkbox-self-checked-disabled') + ).toBeTruthy() }) test('Render checkboxs by configure disabled and indeterminate', () => { const { container } = render( ) - expect( - container.querySelector('.nut-checkbox-icon-indeterminate') - ).toBeTruthy() - expect( - container.querySelector('.nut-checkbox-icon-indeterminate') - ).toHaveClass('nut-checkbox-icon-disabled') + expect(container.querySelector('.nut-checkbox-self-disabled')).toBeTruthy() + // expect( + // container.querySelector('.nut-checkbox-self-indeterminate') + // ).toHaveClass('nut-checkbox-self-disabled') }) test('list model should fireEvent correctly', () => { @@ -181,7 +179,7 @@ test('list model should fireEvent correctly', () => { fireEvent.click(getByTestId('checkbox3')) fireEvent.click(getByTestId('checkbox1')) - const icons = container.querySelectorAll('.nut-checkbox-icon-checked') + const icons = container.querySelectorAll('.nut-checkbox-self-checked') expect(icons.length).toBe(1) expect(limit).toBeCalledWith('min') diff --git a/src/packages/checkbox/checkbox.scss b/src/packages/checkbox/checkbox.scss index 4ec7292b9a..494bb8dd38 100644 --- a/src/packages/checkbox/checkbox.scss +++ b/src/packages/checkbox/checkbox.scss @@ -1,46 +1,82 @@ @import '../checkboxgroup/checkboxgroup.scss'; -.nut-checkbox { - display: flex; - align-items: center; +.nut-checkbox-self { + width: 16px; + height: 16px; + flex-shrink: 0; + position: relative; + box-sizing: border-box; + border-radius: 50%; + + &-normal { + border: 0.5px solid $color-text-disabled; + background: $color-background-overlay; + } - &-icon { - color: $color-text-disabled; - font-size: $checkbox-icon-font-size; + &-checked, + &-disabled, + &-checked-disabled { + &:after { + display: block; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + content: ' '; + background: $color-primary-text; + } } - &-icon-checked { - color: $color-primary; - transition-duration: 0.3s; - transition-property: color, border-color, background-color; + &-checked { + background: linear-gradient( + 90deg, + $color-primary-stop-1 0%, + $color-primary-stop-2 100% + ); + box-shadow: 0px 2px 4px 0px rgba(255, 15, 35, 0.2); + + &:after { + width: 8px; + height: 8px; + border-radius: 50%; + } + } + + &-disabled { + background: $color-text-disabled; - &.nut-checkbox-icon-disabled { - color: $color-primary-disabled-special; + &:after { + width: 8px; + height: 1.5px; } } + &-checked-disabled { + background: $color-primary-disabled-special; + + &:after { + width: 8px; + height: 8px; + border-radius: 50%; + } + } +} + +.nut-checkbox { + display: flex; + align-items: center; + &-label { margin-left: $checkbox-label-margin-left; font-size: $checkbox-label-font-size; color: $checkbox-label-color; + white-space: nowrap; &-disabled { color: $color-text-disabled; } } - &-icon-indeterminate { - color: $color-primary; - - &.nut-checkbox-icon-disabled { - color: $color-primary-disabled-special; - } - } - - &-icon-disabled { - color: $color-text-disabled; - } - &-reverse { flex-direction: row-reverse; diff --git a/src/packages/checkbox/checkbox.taro.tsx b/src/packages/checkbox/checkbox.taro.tsx index 41cdce02e0..b50d83fe7e 100644 --- a/src/packages/checkbox/checkbox.taro.tsx +++ b/src/packages/checkbox/checkbox.taro.tsx @@ -1,11 +1,11 @@ import React, { ReactNode, useContext, useEffect, useState, FC } from 'react' -import { CheckDisabled, Checked, CheckNormal } from '@nutui/icons-react-taro' import classNames from 'classnames' import { View } from '@tarojs/components' import { BasicComponent, ComponentDefaults } from '@/utils/typings' import Context from '../checkboxgroup/context' import { usePropsValue } from '@/utils/use-props-value' import { CheckboxLabelPosition } from '@/packages/checkboxgroup/types' +import Icon from '@/packages/checkbox/icon' export type CheckboxShape = 'button' | 'round' @@ -97,31 +97,31 @@ export const Checkbox: FC< const renderIcon = () => { if (innerDisabled) { if (innerIndeterminate) { - return + return } if (innerChecked) { - return + return } - return + return } if (!innerChecked) { return React.isValidElement(icon) ? ( icon ) : ( - + ) } if (innerIndeterminate) { return React.isValidElement(indeterminateIcon) ? ( indeterminateIcon ) : ( - + ) } return React.isValidElement(activeIcon) ? ( activeIcon ) : ( - + ) } const color = () => { diff --git a/src/packages/checkbox/checkbox.tsx b/src/packages/checkbox/checkbox.tsx index 71c8dd4300..edb8f11b91 100644 --- a/src/packages/checkbox/checkbox.tsx +++ b/src/packages/checkbox/checkbox.tsx @@ -5,12 +5,12 @@ import React, { useEffect, useState, } from 'react' -import { CheckDisabled, Checked, CheckNormal } from '@nutui/icons-react' import classNames from 'classnames' import { BasicComponent, ComponentDefaults } from '@/utils/typings' import Context from '../checkboxgroup/context' import { usePropsValue } from '@/utils/use-props-value' import { CheckboxLabelPosition } from '@/packages/checkboxgroup/types' +import Icon from '@/packages/checkbox/icon' export type CheckboxShape = 'button' | 'round' @@ -102,52 +102,29 @@ export const Checkbox: FunctionComponent< const renderIcon = () => { if (innerDisabled) { if (innerIndeterminate) { - return + return } if (innerChecked) { - return + return } - return + return } if (!innerChecked) { - return React.isValidElement(icon) ? ( - icon - ) : ( - - ) + return React.isValidElement(icon) ? icon : } if (innerIndeterminate) { return React.isValidElement(indeterminateIcon) ? ( indeterminateIcon ) : ( - + ) } return React.isValidElement(activeIcon) ? ( activeIcon ) : ( - + ) } - const color = () => { - const cls = `${classPrefix}-icon ` - if (innerDisabled) { - if (innerChecked && !innerIndeterminate) { - return `${cls}${classPrefix}-icon-checked ${classPrefix}-icon-disabled` - } - if (innerChecked && innerIndeterminate) { - return `${cls}${classPrefix}-icon-indeterminate ${classPrefix}-icon-disabled` - } - return `${cls}${classPrefix}-icon-disabled` - } - if (innerChecked) { - if (innerIndeterminate) { - return `${cls}${classPrefix}-icon-indeterminate` - } - return `${cls}${classPrefix}-icon-checked` - } - return cls - } const renderLabel = () => { return ( ) => { + const { tag, classPrefix, name } = mergeProps( + { + tag: 'div', + classPrefix: 'nut-checkbox-self', + name: 'normal', + }, + props + ) + return createElement<{ className: string }>(tag, { + className: `${classPrefix} ${classPrefix}-${name}`, + }) +} + +export default Icon