index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { BASE_CLASS_PREFIX } from '@douyinfe/semi-foundation/base/constants';
  4. import DefaultLocale from '../locale/source/zh_CN';
  5. import Context, { ContextValue } from './context';
  6. export interface ConfigProviderProps extends ContextValue {}
  7. export default class ConfigProvider extends React.Component<ConfigProviderProps> {
  8. constructor(props: ConfigProviderProps) {
  9. super(props);
  10. }
  11. static propTypes = {
  12. locale: PropTypes.object,
  13. timeZone: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  14. getPopupContainer: PropTypes.func,
  15. direction: PropTypes.oneOf(['ltr', 'rtl']),
  16. };
  17. static defaultProps = {
  18. locale: DefaultLocale,
  19. direction: 'ltr',
  20. };
  21. renderChildren() {
  22. const { direction, children } = this.props;
  23. if (direction === 'rtl') {
  24. return (
  25. <div className={`${BASE_CLASS_PREFIX}-rtl`}>
  26. {children}
  27. </div>
  28. );
  29. }
  30. return children;
  31. }
  32. render() {
  33. const { children, direction, ...rest } = this.props;
  34. return (
  35. <Context.Provider
  36. value={{
  37. direction,
  38. ...rest,
  39. }}
  40. >
  41. {this.renderChildren()}
  42. </Context.Provider>
  43. );
  44. }
  45. }