Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: export useConfig #6501

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/config-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import zhCN from '../../locales/zh-CN'

type Config = {
locale: Locale
children?: ReactNode
}

export const defaultConfigRef: {
Expand All @@ -26,7 +25,9 @@ export function getDefaultConfig() {

const ConfigContext = React.createContext<Config | null>(null)

export type ConfigProviderProps = Config
export type ConfigProviderProps = Config & {
children?: ReactNode
}

export const ConfigProvider: FC<ConfigProviderProps> = props => {
const { children, ...config } = props
Expand Down
13 changes: 13 additions & 0 deletions src/components/config-provider/tests/config-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import Picker from '../../picker'
import SearchBar from '../../search-bar'
import ImageUploader from '../../image-uploader'
import { useConfig } from '../'

import zhCN from '../../../locales/zh-CN'
import zhTW from '../../../locales/zh-TW'
Expand Down Expand Up @@ -94,4 +95,16 @@
expect(container).toMatchSnapshot()
})
})

test('useConfig should only has `locale`', () => {
let config: ReturnType<typeof useConfig>

const Demo = () => {
config = useConfig()
return null
}
render(<Demo />)

expect(Object.keys(config!)).toEqual(['locale'])
})
})
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type {
} from './components/checkbox'
export { default as Collapse } from './components/collapse'
export type { CollapseProps, CollapsePanelProps } from './components/collapse'
export { default as ConfigProvider } from './components/config-provider'
export { default as ConfigProvider, useConfig } from './components/config-provider'
export type { ConfigProviderProps } from './components/config-provider'
export { default as DatePicker } from './components/date-picker'
export type { DatePickerProps, DatePickerRef } from './components/date-picker'
Expand Down
Loading