diff --git a/.gitignore b/.gitignore index 7945eaf..0f0d00c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ yarn-error.log* .now dist esm +examples/**/yarn.lock +examples/**/out +examples/**/.next diff --git a/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap b/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap index 1aaf209..eaf1c54 100644 --- a/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap @@ -4,6 +4,7 @@ exports[`AutoComplete should render correctly 1`] = ` { it('should render correctly', () => { @@ -32,11 +33,13 @@ describe('AutoComplete', () => { expect((input as HTMLInputElement).value).toEqual('value2') }) - it('should render clear icon', () => { + it('should render clear icon', async () => { const wrapper = mount() expect(wrapper.find('svg').length).toBe(0) - wrapper.setProps({ clearable: true }) + await act(async () => { + wrapper.setProps({ clearable: true }) + }) expect(wrapper.find('svg').length).toBe(1) wrapper.find('svg').simulate('click', nativeEvent) @@ -44,11 +47,13 @@ describe('AutoComplete', () => { expect((input as HTMLInputElement).value).toEqual('') }) - it('should reponse width change', () => { + it('should reponse width change', async () => { const wrapper = mount() expect(wrapper.prop('width')).toEqual('100px') + await act(async () => { + wrapper.setProps({ width: '200px' }) + }) - wrapper.setProps({ width: '200px' }) expect(wrapper.prop('width')).toEqual('200px') }) }) diff --git a/components/auto-complete/__tests__/search.test.tsx b/components/auto-complete/__tests__/search.test.tsx index 6b55b91..13b325f 100644 --- a/components/auto-complete/__tests__/search.test.tsx +++ b/components/auto-complete/__tests__/search.test.tsx @@ -1,7 +1,8 @@ import React from 'react' import { mount, render } from 'enzyme' import { AutoComplete } from 'components' -import { nativeEvent } from 'tests/utils' +import { nativeEvent, updateWrapper } from 'tests/utils' +import { act } from 'react-dom/test-utils' const mockOptions = [{ label: 'London', value: 'london' }] describe('AutoComplete Search', () => { @@ -33,9 +34,11 @@ describe('AutoComplete Search', () => { expect(value).not.toEqual('london') }) - it('should render searching component', () => { + it('should render searching component', async () => { let wrapper = mount() - wrapper.setProps({ searching: true }) + await act(async () => { + wrapper.setProps({ searching: true }) + }) wrapper.find('input').at(0).simulate('focus') let dropdown = wrapper.find('.auto-complete-dropdown') expect(dropdown.text()).not.toContain('london') @@ -136,4 +139,15 @@ describe('AutoComplete Search', () => { const wrapper = mount() expect(() => wrapper.unmount()).not.toThrow() }) + + it('value should be reset when freeSolo disabled', async () => { + const wrapper = mount() + const input = wrapper.find('input').at(0) + input.simulate('focus') + input.simulate('change', { target: { value: 'test' } }) + expect((input.getDOMNode() as HTMLInputElement).value).toEqual('test') + input.simulate('blur') + await updateWrapper(wrapper, 200) + expect((input.getDOMNode() as HTMLInputElement).value).toEqual('value') + }) }) diff --git a/components/auto-complete/__tests__/use-input.test.tsx b/components/auto-complete/__tests__/use-input.test.tsx new file mode 100644 index 0000000..21ebd95 --- /dev/null +++ b/components/auto-complete/__tests__/use-input.test.tsx @@ -0,0 +1,60 @@ +import React, { useEffect } from 'react' +import { mount } from 'enzyme' +import { AutoComplete, useInput } from 'components' + +describe('UseInput', () => { + it('should follow change with use-input', () => { + let log = '' + const logSpy = jest.spyOn(console, 'log').mockImplementation(msg => (log = msg)) + const MockInput: React.FC<{ value?: string }> = ({ value }) => { + const { state, setState, bindings } = useInput('') + useEffect(() => { + if (value) setState(value) + }, [value]) + useEffect(() => { + if (state) console.log(state) + }, [state]) + return + } + + const wrapper = mount() + wrapper.setProps({ value: 'test' }) + const input = wrapper.find('input').at(0).getDOMNode() as HTMLInputElement + + expect(input.value).toEqual('test') + expect(log).toContain('test') + + log = '' + wrapper + .find('input') + .at(0) + .simulate('change', { target: { value: 'test-change' } }) + expect(log).toContain('test-change') + logSpy.mockRestore() + }) + + it('should follow change with use-input', () => { + const MockInput: React.FC<{ value?: string; resetValue?: boolean }> = ({ + value, + resetValue, + }) => { + const { reset, setState, bindings } = useInput('') + useEffect(() => { + if (value) setState(value) + }, [value]) + useEffect(() => { + if (resetValue) reset() + }, [resetValue]) + return + } + + const wrapper = mount() + wrapper.setProps({ value: 'test' }) + let input = wrapper.find('input').at(0).getDOMNode() as HTMLInputElement + expect(input.value).toEqual('test') + + wrapper.setProps({ resetValue: true }) + input = wrapper.find('input').at(0).getDOMNode() as HTMLInputElement + expect(input.value).toEqual('') + }) +}) diff --git a/components/auto-complete/auto-complete-item.tsx b/components/auto-complete/auto-complete-item.tsx index 63b102b..a78c315 100644 --- a/components/auto-complete/auto-complete-item.tsx +++ b/components/auto-complete/auto-complete-item.tsx @@ -28,9 +28,10 @@ const AutoCompleteItem: React.FC> children, }) => { const theme = useTheme() - const { value, updateValue, size } = useAutoCompleteContext() + const { value, updateValue, size, updateVisible } = useAutoCompleteContext() const selectHandler = () => { updateValue && updateValue(identValue) + updateVisible && updateVisible(false) } const isActive = useMemo(() => value === identValue, [identValue, value]) @@ -38,7 +39,7 @@ const AutoCompleteItem: React.FC> return (
- {children} + {children}
test-2" +`; + +exports[`Breadcrumbs should render correctly 1`] = ` +"" +`; diff --git a/components/breadcrumbs/__tests__/breadcrumbs.test.tsx b/components/breadcrumbs/__tests__/breadcrumbs.test.tsx new file mode 100644 index 0000000..b0ff8cf --- /dev/null +++ b/components/breadcrumbs/__tests__/breadcrumbs.test.tsx @@ -0,0 +1,75 @@ +import React from 'react' +import { mount } from 'enzyme' +import { Breadcrumbs } from 'components' + +describe('Breadcrumbs', () => { + it('should render correctly', () => { + const wrapper = mount( + + test-1 + , + ) + expect(wrapper.html()).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('should redefined all separators', () => { + const wrapper = mount( + + test-1 + test-2 + , + ) + expect(wrapper.html()).toMatchSnapshot() + expect(wrapper.html()).toContain('*') + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('the specified separator should be redefined', () => { + const wrapper = mount( + + test-1 + % + test-2 + , + ) + expect(wrapper.html()).toContain('%') + }) + + it('should render string when href missing', () => { + let wrapper = mount( + + test-1 + , + ) + let dom = wrapper.find('.breadcrums-item').at(0).getDOMNode() + expect(dom.tagName).toEqual('SPAN') + + wrapper = mount( + + test-1 + , + ) + dom = wrapper.find('.breadcrums-item').at(0).getDOMNode() + expect(dom.tagName).toEqual('A') + + wrapper = mount( + + test-1 + , + ) + dom = wrapper.find('.breadcrums-item').at(0).getDOMNode() + expect(dom.tagName).toEqual('A') + }) + + it('should trigger click event', () => { + const handler = jest.fn() + const wrapper = mount( + + test-1 + , + ) + wrapper.find('.breadcrums-item').at(0).simulate('click') + expect(handler).toHaveBeenCalled() + }) +}) diff --git a/components/breadcrumbs/breadcrumbs-item.tsx b/components/breadcrumbs/breadcrumbs-item.tsx new file mode 100644 index 0000000..2ab1e95 --- /dev/null +++ b/components/breadcrumbs/breadcrumbs-item.tsx @@ -0,0 +1,61 @@ +import Link from '../link' +import { Props as LinkBasicProps } from '../link/link' +import React, { useMemo } from 'react' +import withDefaults from '../utils/with-defaults' +import { pickChild } from '../utils/collections' +import BreadcrumbsSeparator from './breadcrumbs-separator' + +interface Props { + href?: string + nextLink?: boolean + onClick?: (event: React.MouseEvent) => void + className?: string +} + +const defaultProps = { + nextLink: false, + className: '', +} + +type NativeAttrs = Omit, keyof Props> +type NativeLinkAttrs = Omit +export type BreadcrumbsProps = Props & typeof defaultProps & NativeLinkAttrs + +const BreadcrumbsItem = React.forwardRef< + HTMLAnchorElement, + React.PropsWithChildren +>( + ( + { href, nextLink, onClick, children, className, ...props }, + ref: React.Ref, + ) => { + const isLink = useMemo(() => href !== undefined || nextLink, [href, nextLink]) + const [withoutSepChildren] = pickChild(children, BreadcrumbsSeparator) + const clickHandler = (event: React.MouseEvent) => { + onClick && onClick(event) + } + + if (!isLink) { + return ( + + {withoutSepChildren} + + ) + } + + return ( + + {withoutSepChildren} + + ) + }, +) + +const MemoBreadcrumbsItem = React.memo(BreadcrumbsItem) + +export default withDefaults(MemoBreadcrumbsItem, defaultProps) diff --git a/components/breadcrumbs/breadcrumbs-separator.tsx b/components/breadcrumbs/breadcrumbs-separator.tsx new file mode 100644 index 0000000..80e12f5 --- /dev/null +++ b/components/breadcrumbs/breadcrumbs-separator.tsx @@ -0,0 +1,37 @@ +import React from 'react' +import withDefaults from '../utils/with-defaults' + +interface Props { + className?: string +} + +const defaultProps = { + className: '', +} + +type NativeAttrs = Omit, keyof Props> +export type BreadcrumbsProps = Props & typeof defaultProps & NativeAttrs + +const BreadcrumbsSeparator: React.FC> = ({ + children, + className, +}) => { + return ( +
+ {children} + +
+ ) +} + +const MemoBreadcrumbsSeparator = React.memo(BreadcrumbsSeparator) + +export default withDefaults(MemoBreadcrumbsSeparator, defaultProps) diff --git a/components/breadcrumbs/breadcrumbs.tsx b/components/breadcrumbs/breadcrumbs.tsx new file mode 100644 index 0000000..7850b4d --- /dev/null +++ b/components/breadcrumbs/breadcrumbs.tsx @@ -0,0 +1,114 @@ +import React, { ReactNode, useMemo } from 'react' +import useTheme from '../styles/use-theme' +import BreadcrumbsItem from './breadcrumbs-item' +import BreadcrumbsSeparator from './breadcrumbs-separator' +import { addColorAlpha } from '../utils/color' +import { NormalSizes } from '../utils/prop-types' + +interface Props { + size: NormalSizes + separator?: string | ReactNode + className?: string +} + +const defaultProps = { + size: 'medium' as NormalSizes, + separator: '/', + className: '', +} + +type NativeAttrs = Omit, keyof Props> +export type BreadcrumbsProps = Props & typeof defaultProps & NativeAttrs + +const getSize = (size: NormalSizes) => { + const sizes: { [key in NormalSizes]: string } = { + mini: '.75rem', + small: '.875rem', + medium: '1rem', + large: '1.125rem', + } + return sizes[size] +} + +const Breadcrumbs: React.FC> = ({ + size, + separator, + children, + className, +}) => { + const theme = useTheme() + const fontSize = useMemo(() => getSize(size), [size]) + const hoverColor = useMemo(() => { + return addColorAlpha(theme.palette.link, 0.85) + }, [theme.palette.link]) + + const childrenArray = React.Children.toArray(children) + const withSeparatorChildren = childrenArray.map((item, index) => { + if (!React.isValidElement(item)) return item + const last = childrenArray[index - 1] + const lastIsSeparator = React.isValidElement(last) && last.type === BreadcrumbsSeparator + const currentIsSeparator = item.type === BreadcrumbsSeparator + if (!lastIsSeparator && !currentIsSeparator && index > 0) { + return ( + + {separator} + {item} + + ) + } + return item + }) + + return ( + + ) +} + +type MemoBreadcrumbsComponent

= React.NamedExoticComponent

& { + Item: typeof BreadcrumbsItem + Separator: typeof BreadcrumbsSeparator +} +type ComponentProps = Partial & + Omit & + NativeAttrs + +Breadcrumbs.defaultProps = defaultProps + +export default React.memo(Breadcrumbs) as MemoBreadcrumbsComponent diff --git a/components/breadcrumbs/index.ts b/components/breadcrumbs/index.ts new file mode 100644 index 0000000..fe5edd8 --- /dev/null +++ b/components/breadcrumbs/index.ts @@ -0,0 +1,8 @@ +import Breadcrumbs from './breadcrumbs' +import BreadcrumbsItem from './breadcrumbs-item' +import BreadcrumbsSeparator from './breadcrumbs-separator' + +Breadcrumbs.Item = BreadcrumbsItem +Breadcrumbs.Separator = BreadcrumbsSeparator + +export default Breadcrumbs diff --git a/components/button-dropdown/__tests__/__snapshots__/index.test.tsx.snap b/components/button-dropdown/__tests__/__snapshots__/index.test.tsx.snap index abc495c..df8b830 100644 --- a/components/button-dropdown/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/button-dropdown/__tests__/__snapshots__/index.test.tsx.snap @@ -301,8 +301,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -353,8 +353,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -407,7 +407,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -417,8 +417,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -459,7 +459,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -469,8 +469,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -544,7 +544,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -554,8 +554,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -596,7 +596,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -606,8 +606,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -672,8 +672,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -724,8 +724,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -832,8 +832,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -884,8 +884,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -938,7 +938,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -948,8 +948,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -990,7 +990,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1000,8 +1000,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -1075,7 +1075,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1085,8 +1085,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -1127,7 +1127,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1137,8 +1137,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -1203,8 +1203,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -1255,8 +1255,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -1733,8 +1733,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -1785,8 +1785,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -1839,7 +1839,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1849,8 +1849,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -1891,7 +1891,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1901,8 +1901,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -1976,7 +1976,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -1986,8 +1986,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2028,7 +2028,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -2038,8 +2038,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2104,8 +2104,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -2156,8 +2156,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -2264,8 +2264,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -2316,8 +2316,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -2370,7 +2370,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -2380,8 +2380,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2422,7 +2422,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -2432,8 +2432,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2507,7 +2507,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -2517,8 +2517,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2559,7 +2559,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -2569,8 +2569,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -2635,8 +2635,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -2687,8 +2687,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3356,8 +3356,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3408,8 +3408,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3462,7 +3462,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -3472,8 +3472,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -3514,7 +3514,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -3524,8 +3524,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -3599,7 +3599,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -3609,8 +3609,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -3651,7 +3651,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -3661,8 +3661,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -3727,8 +3727,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3779,8 +3779,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3887,8 +3887,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3939,8 +3939,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -3993,7 +3993,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -4003,8 +4003,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -4045,7 +4045,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -4055,8 +4055,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -4130,7 +4130,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -4140,8 +4140,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -4182,7 +4182,7 @@ initialize { box-sizing: border-box; margin: 0; border: none; - background-color: #ff0000; + background-color: #e00; color: #fff; width: 100%; height: 2.5rem; @@ -4192,8 +4192,8 @@ initialize { } button:hover { - border-color: #c00; - background-color: #c00; + border-color: #c50000; + background-color: #c50000; } ", "next": null, @@ -4258,8 +4258,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, @@ -4310,8 +4310,8 @@ initialize { } button:hover { - border-color: #f49b0b; - background-color: #f49b0b; + border-color: #ab570a; + background-color: #ab570a; } ", "next": null, diff --git a/components/capacity/__tests__/__snapshots__/index.test.tsx.snap b/components/capacity/__tests__/__snapshots__/index.test.tsx.snap index 930c48b..1997334 100644 --- a/components/capacity/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/capacity/__tests__/__snapshots__/index.test.tsx.snap @@ -176,7 +176,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; @@ -219,7 +219,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; @@ -386,7 +386,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -429,7 +429,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -633,7 +633,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -676,7 +676,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -752,7 +752,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; @@ -795,7 +795,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; @@ -880,7 +880,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -923,7 +923,7 @@ initialize { span { width: 66.67%; - background-color: #c00; + background-color: #c50000; height: 100%; margin: 0; padding: 0; @@ -1094,7 +1094,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; @@ -1137,7 +1137,7 @@ initialize { span { width: 20%; - background-color: #79ffe1; + background-color: #50e3c2; height: 100%; margin: 0; padding: 0; diff --git a/components/css-baseline/__tests__/__snapshots__/baseline.test.tsx.snap b/components/css-baseline/__tests__/__snapshots__/baseline.test.tsx.snap index 4c5ff67..07fc084 100644 --- a/components/css-baseline/__tests__/__snapshots__/baseline.test.tsx.snap +++ b/components/css-baseline/__tests__/__snapshots__/baseline.test.tsx.snap @@ -213,7 +213,7 @@ initialize { pre code { color: #000; - font-size: 0.75rem; + font-size: 0.8125rem; line-height: 1.25rem; white-space: pre; } @@ -547,7 +547,7 @@ initialize { pre code { color: #fff; - font-size: 0.75rem; + font-size: 0.8125rem; line-height: 1.25rem; white-space: pre; } diff --git a/components/css-baseline/css-baseline.tsx b/components/css-baseline/css-baseline.tsx index 3eeadfb..9f65267 100644 --- a/components/css-baseline/css-baseline.tsx +++ b/components/css-baseline/css-baseline.tsx @@ -216,7 +216,7 @@ const CssBaseline: React.FC> = ({ children }) => { pre code { color: ${theme.palette.foreground}; - font-size: 0.75rem; + font-size: 0.8125rem; line-height: 1.25rem; white-space: pre; } diff --git a/components/dot/__tests__/__snapshots__/index.test.tsx.snap b/components/dot/__tests__/__snapshots__/index.test.tsx.snap index 883959d..a42e9bf 100644 --- a/components/dot/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/dot/__tests__/__snapshots__/index.test.tsx.snap @@ -721,7 +721,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -787,7 +787,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -853,7 +853,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -1443,7 +1443,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -1509,7 +1509,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -1575,7 +1575,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -2165,7 +2165,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -2231,7 +2231,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -2297,7 +2297,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -2887,7 +2887,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -2953,7 +2953,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } @@ -3019,7 +3019,7 @@ initialize { width: 0.625rem; height: 0.625rem; border-radius: 50%; - background-color: #ff0000; + background-color: #e00; user-select: none; } diff --git a/components/grid/__tests__/__snapshots__/index.test.tsx.snap b/components/grid/__tests__/__snapshots__/index.test.tsx.snap index 1f8e917..233206f 100644 --- a/components/grid/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/grid/__tests__/__snapshots__/index.test.tsx.snap @@ -25,6 +25,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 4.166666666666667%; flex-basis: 4.166666666666667%; + } @media only screen and (max-width: 650px) { @@ -32,6 +33,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 4.166666666666667%; flex-basis: 4.166666666666667%; + } } @@ -40,6 +42,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 8.333333333333334%; flex-basis: 8.333333333333334%; + } } @@ -48,6 +51,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 12.5%; flex-basis: 12.5%; + } } @@ -56,6 +60,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 16.666666666666668%; flex-basis: 16.666666666666668%; + } } @@ -64,6 +69,7 @@ exports[`Grid all breakpoint values should be supported 1`] = ` flex-grow: 0; max-width: 20.833333333333336%; flex-basis: 20.833333333333336%; + } } " @@ -159,6 +171,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } @media only screen and (max-width: 650px) { @@ -166,6 +179,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -174,6 +188,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -182,6 +197,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -190,6 +206,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -198,6 +215,7 @@ exports[`Grid css value should be passed through 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } " @@ -293,6 +317,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } @media only screen and (max-width: 650px) { @@ -300,6 +325,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -308,6 +334,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -316,6 +343,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -324,6 +352,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -332,6 +361,7 @@ exports[`Grid decimal spacing should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } " @@ -427,6 +463,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } @media only screen and (max-width: 650px) { @@ -434,6 +471,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -442,6 +480,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -450,6 +489,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -458,6 +498,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -466,6 +507,7 @@ exports[`Grid nested components should be supported 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } }

test
test
test
,
,
," @@ -951,6 +1035,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } @media only screen and (max-width: 650px) { @@ -958,6 +1043,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -966,6 +1052,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -974,6 +1061,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -982,6 +1070,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -990,6 +1079,7 @@ exports[`Grid should render correctly 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } }
test
" @@ -1150,6 +1252,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 0; max-width: 100%; flex-basis: 100%; + } @media only screen and (max-width: 650px) { @@ -1157,6 +1260,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 0; max-width: 100%; flex-basis: 100%; + } } @@ -1165,6 +1269,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -1173,6 +1278,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -1181,6 +1287,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } } @@ -1189,6 +1296,7 @@ exports[`Grid should work correctly when size exceeds 1`] = ` flex-grow: 1; max-width: 100%; flex-basis: 0; + } }
test
" diff --git a/components/grid/__tests__/index.test.tsx b/components/grid/__tests__/index.test.tsx index 72250d0..f40b00a 100644 --- a/components/grid/__tests__/index.test.tsx +++ b/components/grid/__tests__/index.test.tsx @@ -111,4 +111,10 @@ describe('Grid', () => { expect(wrapper.html()).toMatchSnapshot() expect(() => wrapper.unmount()).not.toThrow() }) + + it('Grid should be hidden when value is 0', () => { + let wrapper = mount() + expect(wrapper.find('.item').hasClass('xs')).toBeTruthy() + expect(wrapper.find('.item').html()).toContain('display: none') + }) }) diff --git a/components/grid/basic-item.tsx b/components/grid/basic-item.tsx index 6e0fb97..a433202 100644 --- a/components/grid/basic-item.tsx +++ b/components/grid/basic-item.tsx @@ -32,19 +32,23 @@ type ItemLayoutValue = { grow: number width: string basis: string + display: string } const getItemLayout = (val: BreakpointsValue): ItemLayoutValue => { + const display = val === 0 ? 'display: none;' : '' if (typeof val === 'number') { const width = (100 / 24) * val const ratio = width > 100 ? '100%' : width < 0 ? '0' : `${width}%` return { grow: 0, + display, width: ratio, basis: ratio, } } return { grow: 1, + display, width: '100%', basis: '0', } @@ -62,6 +66,7 @@ const GridBasicItem: React.FC> = ({ alignContent, children, className, + ...props }) => { const theme = useTheme() const classes = useMemo(() => { @@ -77,11 +82,11 @@ const GridBasicItem: React.FC> = ({ xl, } const classString = Object.keys(aligns).reduce((pre, name) => { - if (Boolean(aligns[name]) && aligns[name] !== 0) return `${pre} ${name}` + if (aligns[name] !== undefined && aligns[name] !== false) return `${pre} ${name}` return pre }, '') return classString.trim() - }, [justify, direction, alignItems, alignContent]) + }, [justify, direction, alignItems, alignContent, xs, sm, md, lg, xl]) const layout = useMemo< { @@ -99,7 +104,7 @@ const GridBasicItem: React.FC> = ({ ) return ( -
+
{children} diff --git a/components/image/__tests__/browser.test.tsx b/components/image/__tests__/browser.test.tsx index 7533daa..db6c828 100644 --- a/components/image/__tests__/browser.test.tsx +++ b/components/image/__tests__/browser.test.tsx @@ -59,4 +59,15 @@ describe('Image Browser', () => { const wrapper = mount() expect(() => wrapper.unmount()).not.toThrow() }) + + it('anchor props should be passed through', () => { + const anchorRel = 'noreferrer' + const wrapper = mount( + + + , + ) + const rel = wrapper.find('a').getDOMNode().getAttribute('rel') + expect(anchorRel).toEqual(anchorRel) + }) }) diff --git a/components/image/image-browser.tsx b/components/image/image-browser.tsx index 14f5e1a..ce420f9 100644 --- a/components/image/image-browser.tsx +++ b/components/image/image-browser.tsx @@ -1,21 +1,26 @@ import React, { useMemo } from 'react' import Link from '../link' +import { Props as LinkProps } from '../link/link' import useTheme from '../styles/use-theme' import withDefaults from '../utils/with-defaults' import ImageBrowserHttpsIcon from './image-browser-https-icon' import { getBrowserColors, BrowserColors } from './styles' +type AnchorProps = Omit, keyof LinkProps> + interface Props { title?: string url?: string showFullLink?: boolean invert?: boolean + anchorProps?: AnchorProps className?: string } const defaultProps = { className: '', showFullLink: false, + anchorProps: {} as AnchorProps, invert: false, } @@ -42,12 +47,17 @@ const getTitle = (title: string, colors: BrowserColors) => (
) -const getAddressInput = (url: string, showFullLink: boolean, colors: BrowserColors) => ( +const getAddressInput = ( + url: string, + showFullLink: boolean, + colors: BrowserColors, + anchorProps: AnchorProps, +) => (
- + {showFullLink ? url : getHostFromUrl(url)}

Some content contained within the modal.

diff --git a/components/modal/modal-content.tsx b/components/modal/modal-content.tsx index af443b5..ac7c45b 100644 --- a/components/modal/modal-content.tsx +++ b/components/modal/modal-content.tsx @@ -23,8 +23,9 @@ const ModalContent: React.FC = ({ className, children, ...pro
  • " +`; diff --git a/components/pagination/__tests__/pagination.test.tsx b/components/pagination/__tests__/pagination.test.tsx new file mode 100644 index 0000000..8bf9dfb --- /dev/null +++ b/components/pagination/__tests__/pagination.test.tsx @@ -0,0 +1,148 @@ +import React from 'react' +import { mount } from 'enzyme' +import { Pagination } from 'components' +import { act } from 'react-dom/test-utils' +import { updateWrapper } from 'tests/utils' + +describe('Pagination', () => { + it('should render correctly', () => { + const wrapper = mount() + expect(wrapper.html()).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('the specified page should be activated', async () => { + const wrapper = mount() + expect(wrapper.find('.active').text()).toEqual('2') + await act(async () => { + wrapper.setProps({ page: 10 }) + }) + await updateWrapper(wrapper, 200) + expect(wrapper.find('.active').text()).toEqual('10') + }) + + it('should trigger change event', async () => { + let current = 1 + const handler = jest.fn().mockImplementation(val => (current = val)) + const wrapper = mount() + + await act(async () => { + wrapper.setProps({ page: 10 }) + }) + await updateWrapper(wrapper, 200) + expect(handler).toHaveBeenCalled() + expect(current).toEqual(10) + + const btns = wrapper.find('button') + btns.at(0).simulate('click') + await updateWrapper(wrapper, 200) + expect(current).toEqual(9) + + btns.at(btns.length - 1).simulate('click') + btns.at(btns.length - 1).simulate('click') + btns.at(btns.length - 1).simulate('click') + btns.at(btns.length - 1).simulate('click') + await updateWrapper(wrapper, 200) + expect(current).toEqual(10) + handler.mockRestore() + }) + + it('the page should be rendered to follow the specified limit', async () => { + const wrapper = mount() + expect(wrapper.find('button').length).toBeGreaterThanOrEqual(20) + await act(async () => { + wrapper.setProps({ limit: 5 }) + }) + await updateWrapper(wrapper, 200) + expect(wrapper.find('button').length).toBeLessThanOrEqual(10) + }) + + it('should be render all pages when limit is greater than the total', async () => { + const handler = jest.fn() + const wrapper = mount() + expect(wrapper.find('button').length).toBeGreaterThanOrEqual(15) + wrapper.find('button').at(10).simulate('click') + await updateWrapper(wrapper, 200) + + expect(handler).toHaveBeenCalled() + handler.mockRestore() + }) + + it('omit pages by limit value', async () => { + const wrapper = mount() + const btn4 = wrapper.find('button').at(4) + expect(btn4.text()).toEqual('4') + btn4.simulate('click') + await updateWrapper(wrapper, 200) + let btns = wrapper.find('button').map(btn => btn.text()) + expect(btns.includes('2')).not.toBeTruthy() + expect(btns.includes('1')).toBeTruthy() + expect(btns.includes('3')).toBeTruthy() + expect(btns.includes('4')).toBeTruthy() + expect(btns.includes('5')).toBeTruthy() + expect(btns.includes('6')).not.toBeTruthy() + expect(btns.includes('20')).toBeTruthy() + + const btn5 = wrapper.find('button').at(5) + expect(btn5.text()).toEqual('5') + btn5.simulate('click') + await updateWrapper(wrapper, 200) + btns = wrapper.find('button').map(btn => btn.text()) + expect(btns.includes('1')).toBeTruthy() + expect(btns.includes('2')).not.toBeTruthy() + expect(btns.includes('3')).not.toBeTruthy() + expect(btns.includes('4')).toBeTruthy() + expect(btns.includes('5')).toBeTruthy() + expect(btns.includes('6')).toBeTruthy() + expect(btns.includes('7')).not.toBeTruthy() + expect(btns.includes('8')).not.toBeTruthy() + expect(btns.includes('20')).toBeTruthy() + }) + + it('should trigger change event when ellipsis clicked', async () => { + let current = 20 + const handler = jest.fn().mockImplementation(val => (current = val)) + const wrapper = mount() + const btn = wrapper.find('svg').at(0).parents('button') + btn.at(0).simulate('click') + await updateWrapper(wrapper, 200) + expect(handler).toHaveBeenCalled() + expect(current).toEqual(15) + + await act(async () => { + wrapper.setProps({ page: 1 }) + }) + await updateWrapper(wrapper, 200) + const lastBtn = wrapper.find('svg').at(0).parents('button') + lastBtn.at(0).simulate('click') + await updateWrapper(wrapper, 200) + expect(current).toEqual(1 + 5) + }) + + it('another SVG should be displayed when the mouse is moved in', async () => { + const wrapper = mount() + const svg = wrapper.find('svg').at(0) + const btn = svg.parents('button') + + const html = svg.html() + btn.simulate('mouseEnter') + await updateWrapper(wrapper) + expect(html).not.toEqual(wrapper.find('svg').at(0).html()) + + btn.simulate('mouseLeave') + await updateWrapper(wrapper) + expect(html).toEqual(wrapper.find('svg').at(0).html()) + }) + + it('custom buttons should be display', () => { + const wrapper = mount( + + custom-prev + custom-next + , + ) + const btns = wrapper.find('button') + expect(btns.at(0).text()).toEqual('custom-prev') + expect(btns.at(btns.length - 1).text()).toEqual('custom-next') + }) +}) diff --git a/components/pagination/index.ts b/components/pagination/index.ts new file mode 100644 index 0000000..9a60112 --- /dev/null +++ b/components/pagination/index.ts @@ -0,0 +1,8 @@ +import Pagination from './pagination' +import PaginationPrevious from './pagination-previous' +import PaginationNext from './pagination-next' + +Pagination.Previous = PaginationPrevious +Pagination.Next = PaginationNext + +export default Pagination diff --git a/components/pagination/pagination-context.ts b/components/pagination/pagination-context.ts new file mode 100644 index 0000000..8342ec7 --- /dev/null +++ b/components/pagination/pagination-context.ts @@ -0,0 +1,18 @@ +import React from 'react' +import { tuple } from '../utils/prop-types' +const paginationUpdateTypes = tuple('prev', 'next', 'click') + +export type PaginationUpdateType = typeof paginationUpdateTypes[number] + +export interface PaginationConfig { + isFirst?: boolean + isLast?: boolean + update?: (type: PaginationUpdateType) => void +} + +const defaultContext = {} + +export const PaginationContext = React.createContext(defaultContext) + +export const usePaginationContext = (): PaginationConfig => + React.useContext(PaginationContext) diff --git a/components/pagination/pagination-ellipsis.tsx b/components/pagination/pagination-ellipsis.tsx new file mode 100644 index 0000000..e4d759d --- /dev/null +++ b/components/pagination/pagination-ellipsis.tsx @@ -0,0 +1,60 @@ +import React, { useState } from 'react' +import PaginationItem from './pagination-item' + +interface Props { + isBefore?: boolean + onClick?: (e: React.MouseEvent) => void +} + +const PaginationEllipsis: React.FC = ({ isBefore, onClick }) => { + const [showMore, setShowMore] = useState(false) + + return ( + onClick && onClick(e)} + onMouseEnter={() => setShowMore(true)} + onMouseLeave={() => setShowMore(false)}> + {showMore ? ( + + + + + ) : ( + + + + + + )} + + + + ) +} + +export default PaginationEllipsis diff --git a/components/pagination/pagination-item.tsx b/components/pagination/pagination-item.tsx new file mode 100644 index 0000000..74824d7 --- /dev/null +++ b/components/pagination/pagination-item.tsx @@ -0,0 +1,101 @@ +import React, { useMemo } from 'react' +import useTheme from '../styles/use-theme' +import { addColorAlpha } from '../utils/color' + +interface Props { + active?: boolean + disabled?: boolean + onClick?: (e: React.MouseEvent) => void +} + +type NativeAttrs = Omit, keyof Props> +export type PaginationItemProps = Props & NativeAttrs + +const PaginationItem: React.FC> = ({ + active, + children, + disabled, + onClick, + ...props +}) => { + const theme = useTheme() + const [hover, activeHover] = useMemo( + () => [addColorAlpha(theme.palette.success, 0.1), addColorAlpha(theme.palette.success, 0.8)], + [theme.palette.success], + ) + const clickHandler = (event: React.MouseEvent) => { + if (disabled) return + onClick && onClick(event) + } + + return ( +
  • + + +
  • + ) +} + +export default PaginationItem diff --git a/components/pagination/pagination-next.tsx b/components/pagination/pagination-next.tsx new file mode 100644 index 0000000..d01f893 --- /dev/null +++ b/components/pagination/pagination-next.tsx @@ -0,0 +1,19 @@ +import React from 'react' +import PaginationItem from './pagination-item' +import { usePaginationContext } from './pagination-context' + +export type PaginationNextProps = React.ButtonHTMLAttributes + +const PaginationNext: React.FC> = ({ + children, + ...props +}) => { + const { update, isLast } = usePaginationContext() + return ( + update && update('next')} disabled={isLast} {...props}> + {children} + + ) +} + +export default PaginationNext diff --git a/components/pagination/pagination-pages.tsx b/components/pagination/pagination-pages.tsx new file mode 100644 index 0000000..a90f58f --- /dev/null +++ b/components/pagination/pagination-pages.tsx @@ -0,0 +1,104 @@ +import React, { Dispatch, SetStateAction, useCallback, useMemo } from 'react' +import PaginationItem from './pagination-item' +import PaginationEllipsis from './pagination-ellipsis' + +interface Props { + limit: number + count: number + current: number + setPage: Dispatch> +} + +const PaginationPages: React.FC = ({ limit, count, current, setPage }) => { + const showPages = useMemo(() => { + const oddLimit = limit % 2 === 0 ? limit - 1 : limit + return oddLimit - 2 + }, [limit]) + const middleNumber = (showPages + 1) / 2 + + const [showBeforeEllipsis, showAfterEllipsis] = useMemo(() => { + const showEllipsis = count > limit + return [ + showEllipsis && current > middleNumber + 1, + showEllipsis && current < count - middleNumber, + ] + }, [current, showPages, middleNumber, count, limit]) + const pagesArray = useMemo(() => [...new Array(showPages)], [showPages]) + + const renderItem = useCallback( + (value: number, active: number) => ( + setPage(value)}> + {value} + + ), + [], + ) + const startPages = pagesArray.map((_, index) => { + const value = index + 2 + return renderItem(value, current) + }) + const middlePages = pagesArray.map((_, index) => { + const middleIndexNumber = middleNumber - (index + 1) + const value = current - middleIndexNumber + return ( + setPage(value)}> + {value} + + ) + }) + const endPages = pagesArray.map((_, index) => { + const value = count - (showPages - index) + return renderItem(value, current) + }) + if (count <= limit) { + /* eslint-disable react/jsx-no-useless-fragment */ + return ( + <> + {[...new Array(count)].map((_, index) => { + const value = index + 1 + return ( + setPage(value)}> + {value} + + ) + })} + + ) + /* eslint-enable */ + } + return ( + <> + {renderItem(1, current)} + {showBeforeEllipsis && ( + setPage(last => (last - 5 >= 1 ? last - 5 : 1))} + /> + )} + {showBeforeEllipsis && showAfterEllipsis + ? middlePages + : showBeforeEllipsis + ? endPages + : startPages} + {showAfterEllipsis && ( + setPage(last => (last + 5 <= count ? last + 5 : count))} + /> + )} + {renderItem(count, current)} + + ) +} + +export default PaginationPages diff --git a/components/pagination/pagination-previous.tsx b/components/pagination/pagination-previous.tsx new file mode 100644 index 0000000..79b2bf9 --- /dev/null +++ b/components/pagination/pagination-previous.tsx @@ -0,0 +1,19 @@ +import React from 'react' +import PaginationItem from './pagination-item' +import { usePaginationContext } from './pagination-context' + +export type PaginationNextProps = React.ButtonHTMLAttributes + +const PaginationPrevious: React.FC> = ({ + children, + ...props +}) => { + const { update, isFirst } = usePaginationContext() + return ( + update && update('prev')} disabled={isFirst} {...props}> + {children} + + ) +} + +export default PaginationPrevious diff --git a/components/pagination/pagination.tsx b/components/pagination/pagination.tsx new file mode 100644 index 0000000..8072785 --- /dev/null +++ b/components/pagination/pagination.tsx @@ -0,0 +1,142 @@ +import React, { useEffect, useMemo } from 'react' +import PaginationPrevious from './pagination-previous' +import PaginationNext from './pagination-next' +import PaginationPages from './pagination-pages' +import { PaginationContext, PaginationConfig, PaginationUpdateType } from './pagination-context' +import useCurrentState from '../utils/use-current-state' +import { pickChild } from '../utils/collections' +import { NormalSizes } from '../utils/prop-types' + +interface Props { + size?: NormalSizes + page?: number + initialPage?: number + count?: number + limit?: number + onChange?: (val: number) => void +} + +const defaultProps = { + size: 'medium' as NormalSizes, + initialPage: 1, + count: 1, + limit: 7, +} + +type NativeAttrs = Omit, keyof Props> +export type PaginationProps = Props & typeof defaultProps & NativeAttrs + +type PaginationSize = { + font: string + width: string +} + +const getPaginationSizes = (size: NormalSizes) => { + const sizes: { [key in NormalSizes]: PaginationSize } = { + mini: { + font: '.75rem', + width: '1.25rem', + }, + small: { + font: '.75rem', + width: '1.65rem', + }, + medium: { + font: '.875rem', + width: '2rem', + }, + large: { + font: '1rem', + width: '2.4rem', + }, + } + return sizes[size] +} + +const Pagination: React.FC> = ({ + page: customPage, + initialPage, + count, + limit, + size, + children, + onChange, +}) => { + const [page, setPage, pageRef] = useCurrentState(initialPage) + const [, prevChildren] = pickChild(children, PaginationPrevious) + const [, nextChildren] = pickChild(children, PaginationNext) + + const [prevItem, nextItem] = useMemo(() => { + const hasChildren = (c: any) => React.Children.count(c) > 0 + const prevDefault = prev + const nextDefault = next + return [ + hasChildren(prevChildren) ? prevChildren : prevDefault, + hasChildren(nextChildren) ? nextChildren : nextDefault, + ] + }, [prevChildren, nextChildren]) + const { font, width } = useMemo(() => getPaginationSizes(size), [size]) + + const update = (type: PaginationUpdateType) => { + if (type === 'prev' && pageRef.current > 1) { + setPage(last => last - 1) + } + if (type === 'next' && pageRef.current < count) { + setPage(last => last + 1) + } + } + const values = useMemo( + () => ({ + isFirst: page <= 1, + isLast: page >= count, + update, + }), + [page], + ) + + useEffect(() => { + onChange && onChange(page) + }, [page]) + useEffect(() => { + if (customPage !== undefined) { + setPage(customPage) + } + }, [customPage]) + + return ( + + + + + ) +} + +type MemoPaginationComponent

    = React.NamedExoticComponent

    & { + Previous: typeof PaginationPrevious + Next: typeof PaginationNext +} + +type ComponentProps = Partial & + Omit & + NativeAttrs + +Pagination.defaultProps = defaultProps + +export default React.memo(Pagination) as MemoPaginationComponent diff --git a/components/progress/__tests__/__snapshots__/index.test.tsx.snap b/components/progress/__tests__/__snapshots__/index.test.tsx.snap index db6d0c7..a37497a 100644 --- a/components/progress/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/progress/__tests__/__snapshots__/index.test.tsx.snap @@ -414,7 +414,7 @@ exports[`Progress should work with different types 1`] = ` bottom: 0; transition: all 100ms ease-in; border-radius: 5px; - background-color: #ff0000; + background-color: #e00; width: 1%; }

    " diff --git a/components/radio/__tests__/group.test.tsx b/components/radio/__tests__/group.test.tsx index 9cb15c5..22bd1e1 100644 --- a/components/radio/__tests__/group.test.tsx +++ b/components/radio/__tests__/group.test.tsx @@ -61,6 +61,28 @@ describe('Radio Group', () => { changeHandler.mockRestore() }) + it('the radio value should be support number', () => { + let value = '' + const changeHandler = jest.fn().mockImplementation(val => (value = val)) + const wrapper = mount( + + Option 1 + Option 2 + , + ) + + wrapper + .find('input') + .at(0) + .simulate('change', { + ...nativeEvent, + target: { checked: true }, + }) + expect(changeHandler).toHaveBeenCalled() + expect(value).toEqual(5) + changeHandler.mockRestore() + }) + it('should ignore events when disabled', () => { const changeHandler = jest.fn() const wrapper = mount( diff --git a/components/radio/radio-context.ts b/components/radio/radio-context.ts index b29271b..41fcce4 100644 --- a/components/radio/radio-context.ts +++ b/components/radio/radio-context.ts @@ -1,9 +1,9 @@ import React from 'react' export interface RadioConfig { - updateState?: (value: string) => void + updateState?: (value: string | number) => void disabledAll: boolean - value?: string + value?: string | number inGroup: boolean } diff --git a/components/radio/radio-group.tsx b/components/radio/radio-group.tsx index 802d3ce..21954f1 100644 --- a/components/radio/radio-group.tsx +++ b/components/radio/radio-group.tsx @@ -4,11 +4,11 @@ import { RadioContext } from './radio-context' import { NormalSizes } from 'components/utils/prop-types' interface Props { - value?: string - initialValue?: string + value?: string | number + initialValue?: string | number disabled?: boolean size?: NormalSizes - onChange?: (value: string) => void + onChange?: (value: string | number) => void className?: string useRow?: boolean } @@ -44,8 +44,8 @@ const RadioGroup: React.FC> = ({ useRow, ...props }) => { - const [selfVal, setSelfVal] = useState(initialValue) - const updateState = (nextValue: string) => { + const [selfVal, setSelfVal] = useState(initialValue) + const updateState = (nextValue: string | number) => { setSelfVal(nextValue) onChange && onChange(nextValue) } diff --git a/components/radio/radio.tsx b/components/radio/radio.tsx index b449ad7..15109e4 100644 --- a/components/radio/radio.tsx +++ b/components/radio/radio.tsx @@ -20,7 +20,7 @@ export interface RadioEvent { interface Props { checked?: boolean - value?: string + value?: string | number size?: NormalSizes className?: string disabled?: boolean @@ -77,7 +77,7 @@ const Radio: React.FC> = ({ } setSelfChecked(!selfChecked) if (inGroup) { - updateState && updateState(radioValue as string) + updateState && updateState(radioValue as string | number) } onChange && onChange(selfEvent) } diff --git a/components/select/__tests__/__snapshots__/index.test.tsx.snap b/components/select/__tests__/__snapshots__/index.test.tsx.snap index e3213eb..bbe80b0 100644 --- a/components/select/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/select/__tests__/__snapshots__/index.test.tsx.snap @@ -6,6 +6,7 @@ exports[`Select should render correctly 1`] = ` overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + line-height: calc(1.688 * 16pt); min-width: 0; }
    " -`; - -exports[`Backdrop content should be offset 2`] = ` -"
    test-value
    " -`; - exports[`Backdrop should render correctly 1`] = ` "
    test-value
    " diff --git a/components/shared/__tests__/backdrop.test.tsx b/components/shared/__tests__/backdrop.test.tsx index 9d14ffd..13462a6 100644 --- a/components/shared/__tests__/backdrop.test.tsx +++ b/components/shared/__tests__/backdrop.test.tsx @@ -61,17 +61,28 @@ describe('Backdrop', () => { handler.mockRestore() }) - it('content should be offset', () => { + it('backdrop handler should ignore click events from content', async () => { + const handler = jest.fn() const wrapper = mount( - + test-value , ) - const notOffset = wrapper.html() - expect(wrapper.html()).toMatchSnapshot() - wrapper.setProps({ offsetY: '100' }) - expect(wrapper.html()).toMatchSnapshot() - expect(notOffset).not.toEqual(wrapper.html()) + /** + * In simulation,`mousedown` and `mouseup`not directly triiger `click` event, + * the click event below is just for simulation. + */ + wrapper.find('.content').simulate('mousedown') + wrapper.find('.backdrop').simulate('click', nativeEvent) + wrapper.find('.backdrop').simulate('mouseup') + await updateWrapper(wrapper) + expect(handler).not.toHaveBeenCalled() + + wrapper.find('.backdrop').simulate('mousedown') + wrapper.find('.backdrop').simulate('click', nativeEvent) + wrapper.find('.backdrop').simulate('mouseup') + await updateWrapper(wrapper) + expect(handler).toHaveBeenCalled() }) }) diff --git a/components/shared/__tests__/ellipsis.test.tsx b/components/shared/__tests__/ellipsis.test.tsx index 9a064d6..293d68a 100644 --- a/components/shared/__tests__/ellipsis.test.tsx +++ b/components/shared/__tests__/ellipsis.test.tsx @@ -6,7 +6,7 @@ describe('Ellipsis', () => { it('should render correctly', () => { const wrapper = mount(
    - text + text
    , ) expect(wrapper.html()).toMatchSnapshot() diff --git a/components/shared/backdrop.tsx b/components/shared/backdrop.tsx index d4482d7..eb2fc80 100644 --- a/components/shared/backdrop.tsx +++ b/components/shared/backdrop.tsx @@ -2,11 +2,11 @@ import React, { MouseEvent, useCallback } from 'react' import withDefaults from '../utils/with-defaults' import useTheme from '../styles/use-theme' import CSSTransition from './css-transition' +import useCurrentState from '../utils/use-current-state' interface Props { onClick?: (event: MouseEvent) => void visible?: boolean - offsetY?: number } const defaultProps = { @@ -18,20 +18,32 @@ const defaultProps = { export type BackdropProps = Props & typeof defaultProps const Backdrop: React.FC> = React.memo( - ({ children, onClick, visible, offsetY }) => { + ({ children, onClick, visible }) => { const theme = useTheme() - const clickHandler = useCallback((event: MouseEvent) => { + const [, setIsContentMouseDown, IsContentMouseDownRef] = useCurrentState(false) + const clickHandler = (event: MouseEvent) => { + if (IsContentMouseDownRef.current) return onClick && onClick(event) - }, []) + } const childrenClickHandler = useCallback((event: MouseEvent) => { event.stopPropagation() }, []) + const mouseUpHandler = () => { + if (!IsContentMouseDownRef.current) return + const timer = setTimeout(() => { + setIsContentMouseDown(false) + clearTimeout(timer) + }, 0) + } return ( -
    +
    -
    +
    setIsContentMouseDown(true)}> {children}
    @@ -44,7 +56,7 @@ const Backdrop: React.FC> = React.memo( align-content: center; align-items: center; flex-direction: column; - justify-content: center; + justify-content: space-around; height: 100vh; width: 100vw; overflow: auto; @@ -61,8 +73,9 @@ const Backdrop: React.FC> = React.memo( } .offset { - height: ${offsetY}vh; + height: 0; opacity: 0; + display: flex; background-color: transparent; } diff --git a/components/shared/ellipsis.tsx b/components/shared/ellipsis.tsx index 6a6f218..9ec8c1b 100644 --- a/components/shared/ellipsis.tsx +++ b/components/shared/ellipsis.tsx @@ -1,6 +1,10 @@ import React from 'react' -const Ellipsis: React.FC> = ({ children }) => { +export type EllipsisProps = { + height: string +} + +const Ellipsis: React.FC> = ({ children, height }) => { return ( {children} @@ -9,6 +13,7 @@ const Ellipsis: React.FC> = ({ children }) => { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + line-height: ${height}; min-width: 0; } `} diff --git a/components/styles/themes/dark.ts b/components/styles/themes/dark.ts index b6fa291..adcc36a 100644 --- a/components/styles/themes/dark.ts +++ b/components/styles/themes/dark.ts @@ -18,19 +18,29 @@ export const palette: ZeitUIThemesPalette = { secondary: '#888', code: '#79ffe1', border: '#333', - error: '#ff0000', + error: '#e00', + errorLighter: '#f7d4d6', errorLight: '#ff1a1a', - errorDark: '#c00', + errorDark: '#c50000', success: '#0070f3', + successLighter: '#d3e5ff', successLight: '#3291ff', - successDark: '#0366d6', + successDark: '#0761d1', warning: '#f5a623', + warningLighter: '#ffefcf', warningLight: '#f7b955', - warningDark: '#f49b0b', - cyan: '#79ffe1', + warningDark: '#ab570a', + cyan: '#50e3c2', + cyanLighter: '#aaffec', + cyanLight: '#79ffe1', + cyanDark: '#29bc9b', + violet: '#7928ca', + violetLighter: '#e3d7fc', + violetLight: '#8a63d2', + violetDark: '#4c2889', purple: '#f81ce5', alert: '#ff0080', - violet: '#7928ca', + magenta: '#eb367f', link: '#3291ff', } diff --git a/components/styles/themes/default.ts b/components/styles/themes/default.ts index 9d81c00..9135dd5 100644 --- a/components/styles/themes/default.ts +++ b/components/styles/themes/default.ts @@ -18,19 +18,29 @@ export const palette: ZeitUIThemesPalette = { secondary: '#666', code: '#f81ce5', border: '#eaeaea', - error: '#ff0000', + error: '#e00', errorLight: '#ff1a1a', - errorDark: '#c00', + errorLighter: '#f7d4d6', + errorDark: '#c50000', success: '#0070f3', successLight: '#3291ff', - successDark: '#0366d6', + successLighter: '#d3e5ff', + successDark: '#0761d1', warning: '#f5a623', warningLight: '#f7b955', - warningDark: '#f49b0b', - cyan: '#79ffe1', + warningLighter: '#ffefcf', + warningDark: '#ab570a', + cyan: '#50e3c2', + cyanLighter: '#aaffec', + cyanLight: '#79ffe1', + cyanDark: '#29bc9b', + violet: '#7928ca', + violetLighter: '#e3d7fc', + violetLight: '#8a63d2', + violetDark: '#4c2889', purple: '#f81ce5', alert: '#ff0080', - violet: '#7928ca', + magenta: '#eb367f', link: '#0070f3', } diff --git a/components/styles/themes/index.ts b/components/styles/themes/index.ts index e99530a..dbaea2c 100644 --- a/components/styles/themes/index.ts +++ b/components/styles/themes/index.ts @@ -18,19 +18,29 @@ export interface ZeitUIThemesPalette { code: string border: string success: string + successLighter: string successLight: string successDark: string error: string + errorLighter: string errorLight: string errorDark: string warning: string + warningLighter: string warningLight: string warningDark: string cyan: string - purple: string - alert: string + cyanLighter: string + cyanLight: string + cyanDark: string violet: string + violetLighter: string + violetLight: string + violetDark: string link: string + purple: string + magenta: string + alert: string } export interface ZeitUIThemesExpressiveness { diff --git a/components/tag/__tests__/__snapshots__/index.test.tsx.snap b/components/tag/__tests__/__snapshots__/index.test.tsx.snap index 7ca5465..86bc61f 100644 --- a/components/tag/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/tag/__tests__/__snapshots__/index.test.tsx.snap @@ -319,9 +319,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -356,9 +356,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -618,9 +618,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -655,9 +655,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -917,9 +917,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -954,9 +954,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -1390,9 +1390,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } @@ -1427,9 +1427,9 @@ initialize { font-size: 0.875rem; height: 1.75rem; border-radius: 5px; - border: 1px solid #ff0000; + border: 1px solid #e00; background-color: #fff; - color: #ff0000; + color: #e00; padding: 6px; box-sizing: border-box; } diff --git a/components/text/__tests__/__snapshots__/index.test.tsx.snap b/components/text/__tests__/__snapshots__/index.test.tsx.snap index c5292be..784e0be 100644 --- a/components/text/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/text/__tests__/__snapshots__/index.test.tsx.snap @@ -75,7 +75,7 @@ exports[`Text should work with different styles 1`] = ` }

    test-value

    diff --git a/lib/data/metadata-en-us.json b/lib/data/metadata-en-us.json index ded3353..edc4c22 100644 --- a/lib/data/metadata-en-us.json +++ b/lib/data/metadata-en-us.json @@ -1 +1 @@ -[{"name":"guide","children":[{"name":"getting-started","children":[{"name":"introduction","url":"/en-us/guide/introduction","index":5,"group":"getting-started"},{"name":"installation","url":"/en-us/guide/installation","index":10,"group":"getting-started"},{"name":"Server Render","url":"/en-us/guide/server-render","index":15,"group":"getting-started"}]},{"name":"customization","children":[{"name":"Colors","url":"/en-us/guide/colors","index":100,"group":"customization"},{"name":"Themes","url":"/en-us/guide/themes","index":100,"group":"customization"}]}]},{"name":"components","children":[{"name":"General","children":[{"name":"text","url":"/en-us/components/text","index":10,"group":"General"},{"name":"button","url":"/en-us/components/button","index":100,"group":"General"},{"name":"Code","url":"/en-us/components/code","index":100,"group":"General"},{"name":"Icons","url":"/en-us/components/icons","index":100,"group":"General"}]},{"name":"layout","children":[{"name":"Grid","url":"/en-us/components/grid","index":100,"group":"layout"},{"name":"layout","url":"/en-us/components/layout","index":100,"group":"layout"},{"name":"Page","url":"/en-us/components/page","index":100,"group":"layout"},{"name":"Spacer","url":"/en-us/components/spacer","index":100,"group":"layout"}]},{"name":"Surfaces","children":[{"name":"card","url":"/en-us/components/card","index":100,"group":"Surfaces"},{"name":"collapse","url":"/en-us/components/collapse","index":100,"group":"Surfaces"},{"name":"fieldset","url":"/en-us/components/fieldset","index":100,"group":"Surfaces"}]},{"name":"Data Entry","children":[{"name":"Auto-Complete","url":"/en-us/components/auto-complete","index":100,"group":"Data Entry"},{"name":"Button-Group","url":"/en-us/components/button-group","index":100,"group":"Data Entry"},{"name":"checkbox","url":"/en-us/components/checkbox","index":100,"group":"Data Entry"},{"name":"Input","url":"/en-us/components/input","index":100,"group":"Data Entry"},{"name":"radio","url":"/en-us/components/radio","index":100,"group":"Data Entry"},{"name":"select","url":"/en-us/components/select","index":100,"group":"Data Entry"},{"name":"Slider","url":"/en-us/components/slider","index":100,"group":"Data Entry"},{"name":"textarea","url":"/en-us/components/textarea","index":100,"group":"Data Entry"},{"name":"Toggle","url":"/en-us/components/toggle","index":100,"group":"Data Entry"}]},{"name":"Data Display","children":[{"name":"avatar","url":"/en-us/components/avatar","index":100,"group":"Data Display"},{"name":"Badge","url":"/en-us/components/badge","index":100,"group":"Data Display"},{"name":"Capacity","url":"/en-us/components/capacity","index":100,"group":"Data Display"},{"name":"Description","url":"/en-us/components/description","index":100,"group":"Data Display"},{"name":"Display","url":"/en-us/components/display","index":100,"group":"Data Display"},{"name":"Dot","url":"/en-us/components/dot","index":100,"group":"Data Display"},{"name":"File-Tree","url":"/en-us/components/file-tree","index":100,"group":"Data Display"},{"name":"Image","url":"/en-us/components/image","index":100,"group":"Data Display"},{"name":"keyboard","url":"/en-us/components/keyboard","index":100,"group":"Data Display"},{"name":"Popover","url":"/en-us/components/popover","index":100,"group":"Data Display"},{"name":"Table","url":"/en-us/components/table","index":100,"group":"Data Display"},{"name":"Tag","url":"/en-us/components/tag","index":100,"group":"Data Display"},{"name":"Tooltip","url":"/en-us/components/tooltip","index":100,"group":"Data Display"},{"name":"User","url":"/en-us/components/user","index":100,"group":"Data Display"}]},{"name":"Feedback","children":[{"name":"Loading","url":"/en-us/components/loading","index":100,"group":"Feedback"},{"name":"modal","url":"/en-us/components/modal","index":100,"group":"Feedback"},{"name":"note","url":"/en-us/components/note","index":100,"group":"Feedback"},{"name":"Progress","url":"/en-us/components/progress","index":100,"group":"Feedback"},{"name":"Spinner","url":"/en-us/components/spinner","index":100,"group":"Feedback"},{"name":"toast","url":"/en-us/components/toast","index":100,"group":"Feedback"}]},{"name":"Navigation","children":[{"name":"link","url":"/en-us/components/link","index":100,"group":"Navigation"},{"name":"tabs","url":"/en-us/components/tabs","index":100,"group":"Navigation"},{"name":"button-dropdown","url":"/en-us/components/button-dropdown","index":101,"group":"Navigation"}]},{"name":"Others","children":[{"name":"Divider","url":"/en-us/components/divider","index":100,"group":"Others"},{"name":"Snippet","url":"/en-us/components/snippet","index":100,"group":"Others"}]},{"name":"Utils","children":[{"name":"use-body-scroll","url":"/en-us/components/use-body-scroll","index":100,"group":"Utils"},{"name":"use-click-away","url":"/en-us/components/use-click-away","index":100,"group":"Utils"},{"name":"use-clipboard","url":"/en-us/components/use-clipboard","index":100,"group":"Utils"},{"name":"use-current-state","url":"/en-us/components/use-current-state","index":100,"group":"Utils"},{"name":"use-media-query","url":"/en-us/components/use-media-query","index":100,"group":"Utils"}]}]},{"name":"customization","children":[]}] +[{"name":"guide","children":[{"name":"getting-started","children":[{"name":"introduction","url":"/en-us/guide/introduction","index":5,"group":"getting-started"},{"name":"installation","url":"/en-us/guide/installation","index":10,"group":"getting-started"},{"name":"Server Render","url":"/en-us/guide/server-render","index":15,"group":"getting-started"}]},{"name":"customization","children":[{"name":"Colors","url":"/en-us/guide/colors","index":100,"group":"customization"},{"name":"Themes","url":"/en-us/guide/themes","index":100,"group":"customization"}]}]},{"name":"components","children":[{"name":"General","children":[{"name":"text","url":"/en-us/components/text","index":10,"group":"General"},{"name":"button","url":"/en-us/components/button","index":100,"group":"General"},{"name":"Code","url":"/en-us/components/code","index":100,"group":"General"},{"name":"Icons","url":"/en-us/components/icons","index":100,"group":"General"}]},{"name":"layout","children":[{"name":"Grid","url":"/en-us/components/grid","index":100,"group":"layout"},{"name":"layout","url":"/en-us/components/layout","index":100,"group":"layout"},{"name":"Page","url":"/en-us/components/page","index":100,"group":"layout"},{"name":"Spacer","url":"/en-us/components/spacer","index":100,"group":"layout"}]},{"name":"Surfaces","children":[{"name":"card","url":"/en-us/components/card","index":100,"group":"Surfaces"},{"name":"collapse","url":"/en-us/components/collapse","index":100,"group":"Surfaces"},{"name":"fieldset","url":"/en-us/components/fieldset","index":100,"group":"Surfaces"}]},{"name":"Data Entry","children":[{"name":"Auto-Complete","url":"/en-us/components/auto-complete","index":100,"group":"Data Entry"},{"name":"Button-Group","url":"/en-us/components/button-group","index":100,"group":"Data Entry"},{"name":"checkbox","url":"/en-us/components/checkbox","index":100,"group":"Data Entry"},{"name":"Input","url":"/en-us/components/input","index":100,"group":"Data Entry"},{"name":"radio","url":"/en-us/components/radio","index":100,"group":"Data Entry"},{"name":"select","url":"/en-us/components/select","index":100,"group":"Data Entry"},{"name":"Slider","url":"/en-us/components/slider","index":100,"group":"Data Entry"},{"name":"textarea","url":"/en-us/components/textarea","index":100,"group":"Data Entry"},{"name":"Toggle","url":"/en-us/components/toggle","index":100,"group":"Data Entry"}]},{"name":"Data Display","children":[{"name":"avatar","url":"/en-us/components/avatar","index":100,"group":"Data Display"},{"name":"Badge","url":"/en-us/components/badge","index":100,"group":"Data Display"},{"name":"Capacity","url":"/en-us/components/capacity","index":100,"group":"Data Display"},{"name":"Description","url":"/en-us/components/description","index":100,"group":"Data Display"},{"name":"Display","url":"/en-us/components/display","index":100,"group":"Data Display"},{"name":"Dot","url":"/en-us/components/dot","index":100,"group":"Data Display"},{"name":"File-Tree","url":"/en-us/components/file-tree","index":100,"group":"Data Display"},{"name":"Image","url":"/en-us/components/image","index":100,"group":"Data Display"},{"name":"keyboard","url":"/en-us/components/keyboard","index":100,"group":"Data Display"},{"name":"Popover","url":"/en-us/components/popover","index":100,"group":"Data Display"},{"name":"Table","url":"/en-us/components/table","index":100,"group":"Data Display"},{"name":"Tag","url":"/en-us/components/tag","index":100,"group":"Data Display"},{"name":"Tooltip","url":"/en-us/components/tooltip","index":100,"group":"Data Display"},{"name":"User","url":"/en-us/components/user","index":100,"group":"Data Display"}]},{"name":"Feedback","children":[{"name":"Loading","url":"/en-us/components/loading","index":100,"group":"Feedback"},{"name":"modal","url":"/en-us/components/modal","index":100,"group":"Feedback"},{"name":"note","url":"/en-us/components/note","index":100,"group":"Feedback"},{"name":"Progress","url":"/en-us/components/progress","index":100,"group":"Feedback"},{"name":"Spinner","url":"/en-us/components/spinner","index":100,"group":"Feedback"},{"name":"toast","url":"/en-us/components/toast","index":100,"group":"Feedback"}]},{"name":"Navigation","children":[{"name":"breadcrumbs","url":"/en-us/components/breadcrumbs","index":100,"group":"Navigation"},{"name":"link","url":"/en-us/components/link","index":100,"group":"Navigation"},{"name":"Pagination","url":"/en-us/components/pagination","index":100,"group":"Navigation"},{"name":"tabs","url":"/en-us/components/tabs","index":100,"group":"Navigation"},{"name":"button-dropdown","url":"/en-us/components/button-dropdown","index":101,"group":"Navigation"}]},{"name":"Others","children":[{"name":"Divider","url":"/en-us/components/divider","index":100,"group":"Others"},{"name":"Snippet","url":"/en-us/components/snippet","index":100,"group":"Others"}]},{"name":"Utils","children":[{"name":"use-body-scroll","url":"/en-us/components/use-body-scroll","index":100,"group":"Utils"},{"name":"use-click-away","url":"/en-us/components/use-click-away","index":100,"group":"Utils"},{"name":"use-clipboard","url":"/en-us/components/use-clipboard","index":100,"group":"Utils"},{"name":"use-current-state","url":"/en-us/components/use-current-state","index":100,"group":"Utils"},{"name":"use-media-query","url":"/en-us/components/use-media-query","index":100,"group":"Utils"}]}]},{"name":"customization","children":[]}] diff --git a/lib/data/metadata-zh-cn.json b/lib/data/metadata-zh-cn.json index 124e1e1..059d54a 100644 --- a/lib/data/metadata-zh-cn.json +++ b/lib/data/metadata-zh-cn.json @@ -1 +1 @@ -[{"name":"guide","children":[{"name":"快速上手","children":[{"name":"什么是 ZEIT UI","url":"/zh-cn/guide/introduction","index":5,"group":"快速上手"},{"name":"安装","url":"/zh-cn/guide/installation","index":10,"group":"快速上手"},{"name":"服务端渲染","url":"/zh-cn/guide/server-render","index":15,"group":"快速上手"}]},{"name":"定制化","children":[{"name":"色彩","url":"/zh-cn/guide/colors","index":100,"group":"定制化"},{"name":"主题","url":"/zh-cn/guide/themes","index":100,"group":"定制化"}]}],"localeName":"上手指南"},{"name":"components","children":[{"name":"通用","children":[{"name":"文本 Text","url":"/zh-cn/components/text","index":10,"group":"通用"},{"name":"按钮 Button","url":"/zh-cn/components/button","index":100,"group":"通用"},{"name":"代码 Code","url":"/zh-cn/components/code","index":100,"group":"通用"},{"name":"图标 Icons","url":"/zh-cn/components/icons","index":100,"group":"通用"}]},{"name":"布局","children":[{"name":"栅格 Grid","url":"/zh-cn/components/grid","index":100,"group":"布局"},{"name":"布局 Layout","url":"/zh-cn/components/layout","index":100,"group":"布局"},{"name":"页面 Page","url":"/zh-cn/components/page","index":100,"group":"布局"},{"name":"间距 Spacer","url":"/zh-cn/components/spacer","index":100,"group":"布局"}]},{"name":"表面","children":[{"name":"卡片 Card","url":"/zh-cn/components/card","index":100,"group":"表面"},{"name":"折叠框 Collapse","url":"/zh-cn/components/collapse","index":100,"group":"表面"},{"name":"控件组 Fieldset","url":"/zh-cn/components/fieldset","index":100,"group":"表面"}]},{"name":"数据录入","children":[{"name":"按钮组 Button-Group","url":"/zh-cn/components/button-group","index":100,"group":"数据录入"},{"name":"复选框 Checkbox","url":"/zh-cn/components/checkbox","index":100,"group":"数据录入"},{"name":"输入框 Input","url":"/zh-cn/components/input","index":100,"group":"数据录入"},{"name":"单选框 Radio","url":"/zh-cn/components/radio","index":100,"group":"数据录入"},{"name":"选择器 Select","url":"/zh-cn/components/select","index":100,"group":"数据录入"},{"name":"滑动输入 Slider","url":"/zh-cn/components/slider","index":100,"group":"数据录入"},{"name":"文本输入框 Textarea","url":"/zh-cn/components/textarea","index":100,"group":"数据录入"},{"name":"开关 Toggle","url":"/zh-cn/components/toggle","index":100,"group":"数据录入"},{"name":"自动完成 Auto-Complete","url":"/zh-cn/components/auto-complete","index":104,"group":"数据录入"}]},{"name":"数据展示","children":[{"name":"头像 Avatar","url":"/zh-cn/components/avatar","index":100,"group":"数据展示"},{"name":"徽章 Badge","url":"/zh-cn/components/badge","index":100,"group":"数据展示"},{"name":"容量 Capacity","url":"/zh-cn/components/capacity","index":100,"group":"数据展示"},{"name":"描述 Description","url":"/zh-cn/components/description","index":100,"group":"数据展示"},{"name":"陈列框 Display","url":"/zh-cn/components/display","index":100,"group":"数据展示"},{"name":"点 Dot","url":"/zh-cn/components/dot","index":100,"group":"数据展示"},{"name":"文件树 File Tree","url":"/zh-cn/components/file-tree","index":100,"group":"数据展示"},{"name":"图片 Image","url":"/zh-cn/components/image","index":100,"group":"数据展示"},{"name":"键盘 keyboard","url":"/zh-cn/components/keyboard","index":100,"group":"数据展示"},{"name":"气泡卡片 Popover","url":"/zh-cn/components/popover","index":100,"group":"数据展示"},{"name":"表格 Table","url":"/zh-cn/components/table","index":100,"group":"数据展示"},{"name":"标签 Tag","url":"/zh-cn/components/tag","index":100,"group":"数据展示"},{"name":"文字提示 Tooltip","url":"/zh-cn/components/tooltip","index":100,"group":"数据展示"},{"name":"用户 User","url":"/zh-cn/components/user","index":100,"group":"数据展示"}]},{"name":"反馈","children":[{"name":"加载中 Loading","url":"/zh-cn/components/loading","index":100,"group":"反馈"},{"name":"对话框 Modal","url":"/zh-cn/components/modal","index":100,"group":"反馈"},{"name":"提示 Note","url":"/zh-cn/components/note","index":100,"group":"反馈"},{"name":"进度条 Progress","url":"/zh-cn/components/progress","index":100,"group":"反馈"},{"name":"指示器 Spinner","url":"/zh-cn/components/spinner","index":100,"group":"反馈"},{"name":"通知 Toast","url":"/zh-cn/components/toast","index":100,"group":"反馈"}]},{"name":"导航","children":[{"name":"链接 Link","url":"/zh-cn/components/link","index":100,"group":"导航"},{"name":"选项卡 Tabs","url":"/zh-cn/components/tabs","index":100,"group":"导航"},{"name":"下拉按钮 Btn Dropdown","url":"/zh-cn/components/button-dropdown","index":105,"group":"导航"}]},{"name":"其他","children":[{"name":"分割线 Divider","url":"/zh-cn/components/divider","index":100,"group":"其他"},{"name":"片段 Snippet","url":"/zh-cn/components/snippet","index":100,"group":"其他"}]},{"name":"工具包","children":[{"name":"锁定滚动 useBodyScroll","url":"/zh-cn/components/use-body-scroll","index":100,"group":"工具包"},{"name":"点击他处 useClickAway","url":"/zh-cn/components/use-click-away","index":100,"group":"工具包"},{"name":"剪切板 useClipboard","url":"/zh-cn/components/use-clipboard","index":100,"group":"工具包"},{"name":" 当前值 useCurrentState","url":"/zh-cn/components/use-current-state","index":100,"group":"工具包"},{"name":"媒体查询 useMediaQuery","url":"/zh-cn/components/use-media-query","index":100,"group":"工具包"}]}],"localeName":"所有组件"},{"name":"customization","children":[],"localeName":"定制化"}] +[{"name":"guide","children":[{"name":"快速上手","children":[{"name":"什么是 ZEIT UI","url":"/zh-cn/guide/introduction","index":5,"group":"快速上手"},{"name":"安装","url":"/zh-cn/guide/installation","index":10,"group":"快速上手"},{"name":"服务端渲染","url":"/zh-cn/guide/server-render","index":15,"group":"快速上手"}]},{"name":"定制化","children":[{"name":"色彩","url":"/zh-cn/guide/colors","index":100,"group":"定制化"},{"name":"主题","url":"/zh-cn/guide/themes","index":100,"group":"定制化"}]}],"localeName":"上手指南"},{"name":"components","children":[{"name":"通用","children":[{"name":"文本 Text","url":"/zh-cn/components/text","index":10,"group":"通用"},{"name":"按钮 Button","url":"/zh-cn/components/button","index":100,"group":"通用"},{"name":"代码 Code","url":"/zh-cn/components/code","index":100,"group":"通用"},{"name":"图标 Icons","url":"/zh-cn/components/icons","index":100,"group":"通用"}]},{"name":"布局","children":[{"name":"栅格 Grid","url":"/zh-cn/components/grid","index":100,"group":"布局"},{"name":"布局 Layout","url":"/zh-cn/components/layout","index":100,"group":"布局"},{"name":"页面 Page","url":"/zh-cn/components/page","index":100,"group":"布局"},{"name":"间距 Spacer","url":"/zh-cn/components/spacer","index":100,"group":"布局"}]},{"name":"表面","children":[{"name":"卡片 Card","url":"/zh-cn/components/card","index":100,"group":"表面"},{"name":"折叠框 Collapse","url":"/zh-cn/components/collapse","index":100,"group":"表面"},{"name":"控件组 Fieldset","url":"/zh-cn/components/fieldset","index":100,"group":"表面"}]},{"name":"数据录入","children":[{"name":"按钮组 Button-Group","url":"/zh-cn/components/button-group","index":100,"group":"数据录入"},{"name":"复选框 Checkbox","url":"/zh-cn/components/checkbox","index":100,"group":"数据录入"},{"name":"输入框 Input","url":"/zh-cn/components/input","index":100,"group":"数据录入"},{"name":"单选框 Radio","url":"/zh-cn/components/radio","index":100,"group":"数据录入"},{"name":"选择器 Select","url":"/zh-cn/components/select","index":100,"group":"数据录入"},{"name":"滑动输入 Slider","url":"/zh-cn/components/slider","index":100,"group":"数据录入"},{"name":"文本输入框 Textarea","url":"/zh-cn/components/textarea","index":100,"group":"数据录入"},{"name":"开关 Toggle","url":"/zh-cn/components/toggle","index":100,"group":"数据录入"},{"name":"自动完成 Auto-Complete","url":"/zh-cn/components/auto-complete","index":104,"group":"数据录入"}]},{"name":"数据展示","children":[{"name":"头像 Avatar","url":"/zh-cn/components/avatar","index":100,"group":"数据展示"},{"name":"徽章 Badge","url":"/zh-cn/components/badge","index":100,"group":"数据展示"},{"name":"容量 Capacity","url":"/zh-cn/components/capacity","index":100,"group":"数据展示"},{"name":"描述 Description","url":"/zh-cn/components/description","index":100,"group":"数据展示"},{"name":"陈列框 Display","url":"/zh-cn/components/display","index":100,"group":"数据展示"},{"name":"点 Dot","url":"/zh-cn/components/dot","index":100,"group":"数据展示"},{"name":"文件树 File Tree","url":"/zh-cn/components/file-tree","index":100,"group":"数据展示"},{"name":"图片 Image","url":"/zh-cn/components/image","index":100,"group":"数据展示"},{"name":"键盘 keyboard","url":"/zh-cn/components/keyboard","index":100,"group":"数据展示"},{"name":"气泡卡片 Popover","url":"/zh-cn/components/popover","index":100,"group":"数据展示"},{"name":"表格 Table","url":"/zh-cn/components/table","index":100,"group":"数据展示"},{"name":"标签 Tag","url":"/zh-cn/components/tag","index":100,"group":"数据展示"},{"name":"文字提示 Tooltip","url":"/zh-cn/components/tooltip","index":100,"group":"数据展示"},{"name":"用户 User","url":"/zh-cn/components/user","index":100,"group":"数据展示"}]},{"name":"反馈","children":[{"name":"加载中 Loading","url":"/zh-cn/components/loading","index":100,"group":"反馈"},{"name":"对话框 Modal","url":"/zh-cn/components/modal","index":100,"group":"反馈"},{"name":"提示 Note","url":"/zh-cn/components/note","index":100,"group":"反馈"},{"name":"进度条 Progress","url":"/zh-cn/components/progress","index":100,"group":"反馈"},{"name":"指示器 Spinner","url":"/zh-cn/components/spinner","index":100,"group":"反馈"},{"name":"通知 Toast","url":"/zh-cn/components/toast","index":100,"group":"反馈"}]},{"name":"导航","children":[{"name":"面包屑 Breadcrumbs","url":"/zh-cn/components/breadcrumbs","index":100,"group":"导航"},{"name":"链接 Link","url":"/zh-cn/components/link","index":100,"group":"导航"},{"name":"分页 Pagination","url":"/zh-cn/components/pagination","index":100,"group":"导航"},{"name":"选项卡 Tabs","url":"/zh-cn/components/tabs","index":100,"group":"导航"},{"name":"下拉按钮 Btn Dropdown","url":"/zh-cn/components/button-dropdown","index":105,"group":"导航"}]},{"name":"其他","children":[{"name":"分割线 Divider","url":"/zh-cn/components/divider","index":100,"group":"其他"},{"name":"片段 Snippet","url":"/zh-cn/components/snippet","index":100,"group":"其他"}]},{"name":"工具包","children":[{"name":"锁定滚动 useBodyScroll","url":"/zh-cn/components/use-body-scroll","index":100,"group":"工具包"},{"name":"点击他处 useClickAway","url":"/zh-cn/components/use-click-away","index":100,"group":"工具包"},{"name":"剪切板 useClipboard","url":"/zh-cn/components/use-clipboard","index":100,"group":"工具包"},{"name":" 当前值 useCurrentState","url":"/zh-cn/components/use-current-state","index":100,"group":"工具包"},{"name":"媒体查询 useMediaQuery","url":"/zh-cn/components/use-media-query","index":100,"group":"工具包"}]}],"localeName":"所有组件"},{"name":"customization","children":[],"localeName":"定制化"}] diff --git a/package.json b/package.json index bb740fa..2e25e9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zeit-ui/react", - "version": "1.6.2", + "version": "1.7.3", "main": "dist/index.js", "module": "esm/index.js", "types": "dist/index.d.ts", diff --git a/pages/en-us/components/auto-complete.mdx b/pages/en-us/components/auto-complete.mdx index 89e3d91..38f6c63 100644 --- a/pages/en-us/components/auto-complete.mdx +++ b/pages/en-us/components/auto-complete.mdx @@ -40,10 +40,25 @@ AutoComplete control of input field. } `} /> + { + const options = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + return +} +`} /> + { const allOptions = [ @@ -51,7 +66,7 @@ AutoComplete control of input field. { label: 'Sydney', value: 'sydney' }, { label: 'Shanghai', value: 'shanghai' }, ] - const [options, setOptions] = useState() + const [options, setOptions] = React.useState() const searchHandler = (currentValue) => { if (!currentValue) return setOptions([]) const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) @@ -216,6 +231,31 @@ AutoComplete control of input field. } `} /> + { + const allOptions = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + const [options, setOptions] = React.useState() + const searchHandler = (currentValue) => { + const createOptions = [{ + value: currentValue, label: 'Add "' + currentValue + '"' + }] + if (!currentValue) return setOptions([]) + const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) + const optionsWithCreatable = relatedOptions.length !== 0 ? relatedOptions : createOptions + setOptions(optionsWithCreatable) + } + return +} +`} /> + AutoComplete.Props @@ -235,6 +275,7 @@ AutoComplete control of input field. | **dropdownClassName** | className of dropdown box | `string` | - | - | | **dropdownStyle** | style of dropdown box | `object` | - | - | | **disableMatchWidth** | disable Option from follow parent width | `boolean` | - | `false` | +| **disableFreeSolo** | only values can be changed through Select | `boolean` | - | `false` | | ... | native props | `InputHTMLAttributes` | `'id', 'className', ...` | - | AutoComplete.Item diff --git a/pages/en-us/components/breadcrumbs.mdx b/pages/en-us/components/breadcrumbs.mdx new file mode 100644 index 0000000..ded12ee --- /dev/null +++ b/pages/en-us/components/breadcrumbs.mdx @@ -0,0 +1,136 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Breadcrumbs, Spacer } from 'components' +import NextLink from 'next/link' +import Home from '@zeit-ui/react-icons/home' +import Inbox from '@zeit-ui/react-icons/inbox' + +export const meta = { + title: 'breadcrumbs', + group: 'Navigation', +} + +## Breadcrumbs + +Show where users are in the application. + + + Home + Catalog + Page + +`} /> + + + + Home + Catalog + Page + + + Home + Catalog + Page + + + Home + Catalog + Page + + + Home + Catalog + Page + + +`} /> + + + + Home + Catalog + Page + + + + Home + : + Components + Basic + Button + + +`} /> + + + + Inbox + Page + +`} /> + + + + Home + + + Components + + Breadcrumbs + +`} /> + + +Breadcrumbs.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| **separator** | separator string | `string` | - | `/` | +| **size** | breadcrumbs size | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| ... | native props | `HTMLAttributes` | `'id', 'className', ...` | - | + +Breadcrumbs.Item.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| **href** | link address | `string` | - | - | +| **nextLink** | in `next.js` route | `boolean` | - | `false` | +| **onClick** | click event | `(event: MouseEvent) => void` | - | - | +| ... | native props | `AnchorHTMLAttributes` | `'id', 'className', ...` | - | + +Breadcrumbs.Separator.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | native props | `HTMLAttributes` | `'id', 'className', ...` | - | + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children} diff --git a/pages/en-us/components/grid.mdx b/pages/en-us/components/grid.mdx index b4ed13c..242bfc6 100644 --- a/pages/en-us/components/grid.mdx +++ b/pages/en-us/components/grid.mdx @@ -79,6 +79,26 @@ and very small size. Of course, it still supports dynamic props and custom break } `} /> + { + const MockItem = () => { + return + } + return ( + + + + + + + ) +} +`} /> + + `} /> @@ -77,6 +77,7 @@ Display image content. | **url** | show url on browser address input | `string` | - | - | | **showFullLink** | show full url | `boolean` | - | `false` | | **invert** | invert colors | `boolean` | - | `false` | +| **anchorProps** | props of element `a` | `AnchorHTMLAttributes` | - | `{}` | | ... | native props | `HTMLAttributes` | `'id', 'className', ...` | - | diff --git a/pages/en-us/components/pagination.mdx b/pages/en-us/components/pagination.mdx new file mode 100644 index 0000000..3c7fd85 --- /dev/null +++ b/pages/en-us/components/pagination.mdx @@ -0,0 +1,108 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Pagination, Spacer } from 'components' +import ChevronRight from '@zeit-ui/react-icons/chevronRight' +import ChevronLeft from '@zeit-ui/react-icons/chevronLeft' +import ChevronRightCircle from '@zeit-ui/react-icons/chevronRightCircle' +import ChevronLeftCircle from '@zeit-ui/react-icons/chevronLeftCircle' +import ChevronRightCircleFill from '@zeit-ui/react-icons/chevronRightCircleFill' +import ChevronLeftCircleFill from '@zeit-ui/react-icons/chevronLeftCircleFill' + +export const meta = { + title: 'Pagination', + group: 'Navigation', +} + +## Pagination + +Navigation and identification between multiple pages. + + +`} /> + + + + + + + + +`} /> + + + + + + + + + + + + + + + + + +`} /> + + + + + + + +`} /> + + +Pagination.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| **initialPage** | the page selected by default | `number` | - | 1 | +| **page** | current page | `number` | - | 1 | +| **count** | the total number of pages | `number` | - | 1 | +| **limit** | limit of display page | `number` | - | 7 | +| **size** | pagination size | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| **onChange** | change event | `(page: number) => void` | - | - | +| ... | native props | `HTMLAttributes` | `'id', 'className', ...` | - | + +Pagination.Previous.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | native props | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +Pagination.Next.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | native props | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children} diff --git a/pages/en-us/guide/colors.mdx b/pages/en-us/guide/colors.mdx index 1c5ea7d..fd42821 100644 --- a/pages/en-us/guide/colors.mdx +++ b/pages/en-us/guide/colors.mdx @@ -16,8 +16,8 @@ Default colors for themes. ### PRIMARY -You can use any color in any where, all colors change with the theme. -want to customize some colors? Read Themes to learn more. +You can use any color anywhere, all colors change with the theme. +If you want to customize your colors, please read Themes to learn more. Get palette from useTheme.}> @@ -38,27 +38,43 @@ const myComponent = () => { -### Status +### STATUS Use different colors to express more emotional changes. -#### Success +### Success + -#### Error +### Error + -#### Warning +### Warning + -#### Highlight +### Cyan + + + + +### Violet + + + + + +### Highlight + + diff --git a/pages/en-us/guide/installation.mdx b/pages/en-us/guide/installation.mdx index b1d6158..5ede6cf 100644 --- a/pages/en-us/guide/installation.mdx +++ b/pages/en-us/guide/installation.mdx @@ -13,7 +13,7 @@ export const meta = { Ensure your have the latest version of NodeJS, and a package manager: NPM or Yarn. -If you want to see a complete example, please browser our sample collection. +If you want to see a complete example, please browse our sample collection. 1. Run script to download: @@ -46,7 +46,7 @@ const Application = () => ( - 3. Use components in any where: + 3. Use the Zeit UI components anywhere: @@ -64,7 +64,7 @@ const MyComponent = () => ### Single component -ZEIT UI supports import components when you actually need.(`tree-shaking`) +ZEIT UI supports importing single, specific components when you need them. This is referred to as `tree-shaking`. E.g. @@ -85,17 +85,16 @@ const MyComponent = () => ### Create React App A React project created by create-react-app can -also easily use `@zeit-ui/react`. You don't need to make any changes, just install and use. +also easily use `@zeit-ui/react`. You don't need to make any changes, just install and use. We have a +sample project related to create react app here. -We have a -sample project related to create react app here. If you want to `tree-shaking`, -please refer to this example. +If you want to eject certain configs, `tree-shaking`, please refer to this example. ### Next.js -In the `next.js` project, you need to customize the app.jsx entry file to load provider. +In the `next.js` project, you need to customize the app.jsx entry file to load the provider. Start your NextJS project with this example. export default ({ children }) => {children} diff --git a/pages/en-us/guide/introduction.mdx b/pages/en-us/guide/introduction.mdx index 932c0bc..99e2864 100644 --- a/pages/en-us/guide/introduction.mdx +++ b/pages/en-us/guide/introduction.mdx @@ -14,8 +14,8 @@ export const meta = { `@zeit-ui/react` is a React implementation for styles originating from Vercel's design. -The design of the **Vercel** is concise and aesthetic feeling, this is an important reason for popular of Vercel. -Now you can use them at will in React. +The design of **Vercel** is concise and aesthetic, this is an important reason for popularity of Vercel. +Now you can implement the styles in your own React project. ZEIT UI is an unofficial organization, all our projects are open source. @@ -25,7 +25,7 @@ ZEIT UI is an unofficial organization, all our projects are open source. - Chat on Spectrum - Report an issue -- Welcome share your feedback and ideas. We also love PRs. +- We welcome feedback and ideas. We also love PRs. diff --git a/pages/en-us/guide/server-render.mdx b/pages/en-us/guide/server-render.mdx index 427803c..c5ea11e 100644 --- a/pages/en-us/guide/server-render.mdx +++ b/pages/en-us/guide/server-render.mdx @@ -15,21 +15,18 @@ export const meta = { All Components of `@zeit-ui/react` are compatible with **Server Render**. In fact, the document you see now is rendered by the server. - You just need a SPA application? - It is recommended to skip this section. + If you are looking to build a SPA (single page application), + please feel free to skip this section. -Will using server-side rendering make my application lose the advantages of SPA? Maybe you can use the `hybrid render` application, -Read +If you are concerned about losing the advantages of a Single Page Application by implementing server-side rendering, you can use the `hybrid render` application. +Plese read the post from the Next.js team to learn more. In addition, for server-side render and web applications, -we strongly recommend that you read this famous post - - 7-principles-of-rich-web-applications - from Guillermo Rauch. +we strongly recommend that you read this famous post 7-principles-of-rich-web-applications from Guillermo Rauch. @@ -40,7 +37,7 @@ In `next.js` framework, you need customization file `_document.js`, please refer to Next.js document here to create file `_document.js`. -Then we add the following codes to the file: +Then we add the following code to the file: ```js import Document, { Html, Head, Main, NextScript } from 'next/document' @@ -66,13 +63,13 @@ class MyDocument extends Document { } ``` -Here's an examples that might help you: _document.jsx. +Here's an example of what your `_document.js` file should look like: _document.jsx. ### Custom Server -In the custom server, also get the style set from function `CssBaseline.flush`. +In the custom server, also get the style set from function `CssBaseline.flush` as shown below. ```js import React from 'react' diff --git a/pages/en-us/guide/themes.mdx b/pages/en-us/guide/themes.mdx index d5ab7d3..4d21a78 100644 --- a/pages/en-us/guide/themes.mdx +++ b/pages/en-us/guide/themes.mdx @@ -8,7 +8,7 @@ export const meta = { ## Themes -`@zeit-ui/react` support **Dark Mode** now. You can switch theme at any time through a very simple API, no third-party styles or configs. +`@zeit-ui/react` now support **Dark Mode**. You can switch theme at any time through a very simple API, no third-party styles or configs. @@ -48,14 +48,14 @@ const App = () => { ### Customizing theme -Customize theme is very simple in `@zeit-ui/react`, you just need to provide a new theme `Object`, +Customizing a theme is very simple in `@zeit-ui/react`, you just need to provide a new theme `Object`, and all the components will change automatically. Here is a complete sample project for reference. -Of course, if a *component* doesn't use your customize variables, it doesn't make any additional **changes** or **rendering**. +Of course, if a *component* doesn't use your customized variables, it doesn't make any additional **changes** or **rendering**. -The more changes you custom, the more Components Re-Render. +The more changes you customise, the more Components will Re-Render. ```jsx import { CssBaseline, ZeitProvider } from '@zeit-ui/react' @@ -103,7 +103,7 @@ If you don't use TypeScript, to learn more about preset types, see ( #### Overriding styles with `inline-style` -Any `inline-style` works correctly on the component. +Defining an `inline-style` will also correctly override the component. ```jsx const MyPage = () => ( diff --git a/pages/zh-cn/components/auto-complete.mdx b/pages/zh-cn/components/auto-complete.mdx index d83ab30..f3fc33e 100644 --- a/pages/zh-cn/components/auto-complete.mdx +++ b/pages/zh-cn/components/auto-complete.mdx @@ -26,6 +26,21 @@ export const meta = { } `} /> + { + const options = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + return +} +`} /> + + + { + const allOptions = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + const [options, setOptions] = React.useState() + const searchHandler = (currentValue) => { + const createOptions = [{ + value: currentValue, label: 'Add "' + currentValue + '"' + }] + if (!currentValue) return setOptions([]) + const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) + const optionsWithCreatable = relatedOptions.length !== 0 ? relatedOptions : createOptions + setOptions(optionsWithCreatable) + } + return +} +`} /> + AutoComplete.Props @@ -236,6 +277,7 @@ export const meta = { | **dropdownClassName** | 自定义下拉框的类名 | `string` | - | - | | **dropdownStyle** | 自定义下拉框的样式 | `object` | - | - | | **disableMatchWidth** | 禁止 Option 跟随父元素的宽度 | `boolean` | - | `false` | +| **disableFreeSolo** | 只允许通过 Select 事件更改值 (禁止 Input 输入随意值) | `boolean` | - | `false` | | ... | 原生属性 | `InputHTMLAttributes` | `'id', 'className', ...` | - | AutoComplete.Item diff --git a/pages/zh-cn/components/breadcrumbs.mdx b/pages/zh-cn/components/breadcrumbs.mdx new file mode 100644 index 0000000..2fc0dc1 --- /dev/null +++ b/pages/zh-cn/components/breadcrumbs.mdx @@ -0,0 +1,136 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Breadcrumbs, Spacer } from 'components' +import NextLink from 'next/link' +import Home from '@zeit-ui/react-icons/home' +import Inbox from '@zeit-ui/react-icons/inbox' + +export const meta = { + title: '面包屑 Breadcrumbs', + group: '导航', +} + +## Breadcrumbs / 面包屑导航 + +显示用户在应用中的层级位置。 + + + Home + Catalog + Page + +`} /> + + + + Home + Catalog + Page + + + Home + Catalog + Page + + + Home + Catalog + Page + + + Home + Catalog + Page + + +`} /> + + + + Home + Catalog + Page + + + + Home + : + Components + Basic + Button + + +`} /> + + + + Inbox + Page + +`} /> + + + + Home + + + Components + + Breadcrumbs + +`} /> + + +Breadcrumbs.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| **separator** | 分隔符 | `string` | - | `/` | +| **size** | 面包屑导航的大小 | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| ... | 原生属性 | `HTMLAttributes` | `'id', 'className', ...` | - | + +Breadcrumbs.Item.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| **href** | 链接地址 | `string` | - | - | +| **nextLink** | 是否为 `next.js` 路由 | `boolean` | - | `false` | +| **onClick** | 点击事件 | `(event: MouseEvent) => void` | - | - | +| ... | 原生属性 | `AnchorHTMLAttributes` | `'id', 'className', ...` | - | + +Breadcrumbs.Separator.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | 原生属性 | `HTMLAttributes` | `'id', 'className', ...` | - | + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children} diff --git a/pages/zh-cn/components/grid.mdx b/pages/zh-cn/components/grid.mdx index c0b178b..084cc9e 100644 --- a/pages/zh-cn/components/grid.mdx +++ b/pages/zh-cn/components/grid.mdx @@ -79,6 +79,26 @@ export const meta = { } `} /> + { + const MockItem = () => { + return + } + return ( + + + + + + + ) +} +`} /> + diff --git a/pages/zh-cn/components/pagination.mdx b/pages/zh-cn/components/pagination.mdx new file mode 100644 index 0000000..66721c0 --- /dev/null +++ b/pages/zh-cn/components/pagination.mdx @@ -0,0 +1,109 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Pagination, Spacer } from 'components' +import ChevronRight from '@zeit-ui/react-icons/chevronRight' +import ChevronLeft from '@zeit-ui/react-icons/chevronLeft' +import ChevronRightCircle from '@zeit-ui/react-icons/chevronRightCircle' +import ChevronLeftCircle from '@zeit-ui/react-icons/chevronLeftCircle' +import ChevronRightCircleFill from '@zeit-ui/react-icons/chevronRightCircleFill' +import ChevronLeftCircleFill from '@zeit-ui/react-icons/chevronLeftCircleFill' + +export const meta = { + title: '分页 Pagination', + group: '导航', +} + +## Pagination / 分页 + +多个页面之间的导航与鉴别。 + + +`} /> + + + + + + + + +`} /> + + + + + + + + + + + + + + + + + +`} /> + + + + + + + +`} /> + + +Pagination.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| **initialPage** | 初始选中的页面 | `number` | - | 1 | +| **page** | 当前页码 | `number` | - | 1 | +| **count** | 页码数量 | `number` | - | 1 | +| **limit** | 一次可展示页面的最大值 | `number` | - | 7 | +| **size** | 组件的大小 | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| **onChange** | 分页器的事件 | `(page: number) => void` | - | - | +| ... | 原生属性 | `HTMLAttributes` | `'id', 'className', ...` | - | + +Pagination.Previous.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | 原生属性 | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +Pagination.Next.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| ... | 原生属性 | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children}