Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
141 changes: 0 additions & 141 deletions src/locales/base.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const enUS: BaseLang = {
const enUS: Locales = {
save: 'Save',
confirm: 'Confirm',
cancel: 'Cancel',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/id-ID.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const idID: BaseLang = {
const idID: Locales = {
save: 'Simpan',
confirm: 'Konfirmasi',
cancel: 'Batal',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/tr-TR.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const trTR: BaseLang = {
const trTR: Locales = {
save: 'Kaydet',
confirm: 'Onayla',
cancel: 'İptal',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhCN: BaseLang = {
const zhCN: Locales = {
save: '保存',
confirm: '确认',
cancel: '取消',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhCN: BaseLang = {
const zhCN: Locales = {
save: '保存',
confirm: '確認',
cancel: '取消',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh-UG.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseLang } from './base'
import { Locales } from '@/types'

const zhUG: BaseLang = {
const zhUG: Locales = {
save: 'ساقلاش',
confirm: 'ھەئە',
cancel: 'ياق',
Expand Down
29 changes: 10 additions & 19 deletions src/packages/configprovider/configprovider.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@ import kebabCase from 'lodash.kebabcase'
import isEqual from 'react-fast-compare'
import { View } from '@tarojs/components'
import { useMemo } from '@/hooks/use-memo'
import { BasicComponent } from '@/utils/typings'
import { BaseLang } from '@/locales/base'
import zhCN from '@/locales/zh-CN'
import type { NutCSSVariables } from './types'

export interface ConfigProviderProps extends BasicComponent {
locale: BaseLang
direction?: ConfigProviderDirection
theme?: Record<string | NutCSSVariables, string>
}

export type ConfigProviderDirection = 'ltr' | 'rtl' | undefined

const classPrefix = 'nut-configprovider'
import { TaroConfigProviderProps, Locales as LocalesType } from '@/types'

type Locales = Partial<LocalesType>
export const defaultConfigRef: {
current: ConfigProviderProps
current: TaroConfigProviderProps<Locales>
} = {
current: {
locale: zhCN,
direction: 'ltr',
},
}

export const setDefaultConfig = (config: ConfigProviderProps) => {
export const setDefaultConfig = (config: TaroConfigProviderProps<Locales>) => {
defaultConfigRef.current = config
}

export const getDefaultConfig = () => {
return defaultConfigRef.current
}

const ConfigContext = createContext<ConfigProviderProps | null>(null)
const ConfigContext = createContext<TaroConfigProviderProps<Locales> | null>(
null
)

export const useConfig = () => {
return useContext(ConfigContext) ?? getDefaultConfig()
Expand All @@ -56,10 +47,10 @@ export const useRtl = () => {
}

export const ConfigProvider: FunctionComponent<
Partial<ConfigProviderProps & BasicComponent>
Partial<TaroConfigProviderProps<Locales>>
> = (props) => {
const { style, className, children, direction, ...config } = props

const classPrefix = 'nut-configprovider'
const mergedConfig = useMemo(
() => {
return {
Expand All @@ -74,7 +65,7 @@ export const ConfigProvider: FunctionComponent<
const nextTheme = next[index]
return !isEqual(prevTheme, nextTheme)
})
) as ConfigProviderProps
) as TaroConfigProviderProps<Locales>

const cssVarStyle = React.useMemo(() => {
return convertThemeVarsToCSSVars(mergedConfig.theme || {})
Expand Down
29 changes: 11 additions & 18 deletions src/packages/configprovider/configprovider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,32 @@ import classNames from 'classnames'
import kebabCase from 'lodash.kebabcase'
import isEqual from 'react-fast-compare'
import { useMemo } from '@/hooks/use-memo'
import { BasicComponent } from '@/utils/typings'
import { BaseLang } from '@/locales/base'
import zhCN from '@/locales/zh-CN'
import type { NutCSSVariables } from './types'
import { inBrowser } from '@/utils'
import { WebConfigProviderProps, Locales as LocalesType } from '@/types'

export interface ConfigProviderProps extends BasicComponent {
locale: BaseLang
direction?: ConfigProviderDirection
theme?: Record<string | NutCSSVariables, string>
}

export type ConfigProviderDirection = 'ltr' | 'rtl' | undefined

const classPrefix = 'nut-configprovider'
type Locales = Partial<LocalesType>

export const defaultConfigRef: {
current: ConfigProviderProps
current: WebConfigProviderProps<Locales>
} = {
current: {
locale: zhCN,
direction: 'ltr',
},
}

export const setDefaultConfig = (config: ConfigProviderProps) => {
export const setDefaultConfig = (config: WebConfigProviderProps<Locales>) => {
defaultConfigRef.current = config
}

export const getDefaultConfig = () => {
return defaultConfigRef.current
}

const ConfigContext = createContext<ConfigProviderProps | null>(null)
const ConfigContext = createContext<WebConfigProviderProps<Locales> | null>(
null
)

export const useConfig = () => {
return useContext(ConfigContext) ?? getDefaultConfig()
Expand All @@ -58,10 +51,10 @@ export const useRtl = () => {
}

export const ConfigProvider: FunctionComponent<
Partial<ConfigProviderProps & BasicComponent>
Partial<WebConfigProviderProps<Locales>>
> = (props) => {
const { style, className, children, direction, ...config } = props

const classPrefix = 'nut-configprovider'
const mergedConfig = useMemo(
() => {
return {
Expand All @@ -76,7 +69,7 @@ export const ConfigProvider: FunctionComponent<
const nextTheme = next[index]
return !isEqual(prevTheme, nextTheme)
})
) as ConfigProviderProps
) as WebConfigProviderProps<Locales>

const cssVarStyle = React.useMemo(() => {
return convertThemeVarsToCSSVars(mergedConfig.theme || {})
Expand Down
6 changes: 3 additions & 3 deletions src/packages/configprovider/index.taro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from './configprovider.taro'

export type {
ConfigProviderProps,
ConfigProviderDirection,
} from './configprovider.taro'
TaroConfigProviderProps,
PageDirection as ConfigProviderDirection,
} from '@/types'
export type { NutCSSVariables } from './types'
export { useConfig, setDefaultConfig, getDefaultConfig, useRtl }
export default ConfigProvider
6 changes: 3 additions & 3 deletions src/packages/configprovider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from './configprovider'

export type {
ConfigProviderProps,
ConfigProviderDirection,
} from './configprovider'
WebConfigProviderProps,
PageDirection as ConfigProviderDirection,
} from '@/types'
export type { NutCSSVariables } from './types'
export { useConfig, setDefaultConfig, getDefaultConfig, useRtl }
export default ConfigProvider
Loading
Loading