--- localeCode: zh-CN order: 72 category: 其他 title: ConfigProvider 全局配置 icon: doc-configprovider dir: column brief: 为组件提供统一的全局化配置。 --- ## 代码演示 ### 如何引入 ```jsx import import { ConfigProvider } from '@douyinfe/semi-ui'; ``` ### 基本用法 通过传入 timeZone 参数,用户可以为时间类组件配置时区: ```jsx live=true dir="column" hideInDSM import React, { useMemo, useState } from 'react'; import { ConfigProvider, Select, DatePicker, TimePicker } from '@douyinfe/semi-ui'; function Demo(props = {}) { const [timeZone, setTimeZone] = useState('GMT+08:00'); const defaultTimestamp = 1581599305265; const gmtList = useMemo(() => { const list = []; for (let hourOffset = -11; hourOffset <= 14 ; hourOffset++) { const prefix = hourOffset >= 0 ? '+' : '-'; const hOffset = Math.abs(parseInt(hourOffset, 10)); list.push(`GMT${prefix}${String(hOffset).padStart(2, '0')}:00`); } return list; }, []); return (
Select Time Zone:


console.log('DatePicker changed: ', date, dateString)} />

console.log('DatePicker changed: ', date, dateString)} />
); } ``` ### RTL/LTR 全局配置 `direction` 可以改变组件的文本方向(1.8.0)。 `rtl` 表示从右到左 (类似希伯来语或阿拉伯语), `ltr` 表示从左到右 (类似中文、英语等大部分语言)。 特殊组件: - Modal,Notification,Toast 的命令式调用需要通过 prop 传 `direction`。 - 如果你想对有方向性的 Icon 做 RTL 国际化,需要自己单独进行处理。我们认为对 Icon 进行 RTL 会让它变得难以理解和维护。其他组件内的 icon Semi 已经做了 RTL 适配。 - Table 的固定列或表头,树形数据,虚拟化表格暂不支持 RTL,Slider 暂不支持 RTL ```jsx live=true dir="column" hideInDSM import React, { useState } from 'react'; import { ConfigProvider, ButtonGroup, Button, Row, Col, Notification, DatePicker, TimePicker, Timeline, Popover, Tag, Tooltip, Badge, Avatar, Steps, Pagination, Modal, Breadcrumb, Rating, Nav, Spin, Cascader, Radio, Select, Input, Typography, TextArea, Checkbox, Switch } from '@douyinfe/semi-ui'; import { IconVigoLogo, IconEdit, IconCamera, IconList, IconSidebar, IconChevronDown } from '@douyinfe/semi-icons'; function Demo(props = {}) { const { Option } = Select; const [direction, setDirection] = useState(); const flexStyle = { display: 'flex', marginBottom: 32, flexWrap: 'wrap' }; const titleStyle = { margin: '50px 0 16px 0' }; const rowStyle = { margin: '16px 10px' }; const badgeStyle = { width: '42px', height: '42px', borderRadius: '4px', display: 'inline-block', }; const tagStyle = { marginRight: 8, marginBottom: 8 }; const buttonStyle = { ...tagStyle }; const opts = { title: 'Hi,Bytedance', content: 'ies dance dance dance', duration: 3, direction, }; const treeData = [ { label: '浙江省', value: 'zhejiang', children: [ { label: '杭州市', value: 'hangzhou', children: [ { label: '西湖区', value: 'xihu', }, { label: '萧山区', value: 'xiaoshan', }, { label: '临安区', value: 'linan', }, ], }, { label: '宁波市', value: 'ningbo', children: [ { label: '海曙区', value: 'haishu', }, { label: '江北区', value: 'jiangbei', } ] }, ], } ]; return (

Buttons



Input







Suffix} showClear>