index.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // eslint-disable-next-line
  7. export interface ConfigProviderProps extends ContextValue {}
  8. export default class ConfigProvider extends React.Component<ConfigProviderProps> {
  9. static propTypes = {
  10. locale: PropTypes.object,
  11. timeZone: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  12. getPopupContainer: PropTypes.func,
  13. direction: PropTypes.oneOf(['ltr', 'rtl']),
  14. };
  15. static defaultProps = {
  16. locale: DefaultLocale,
  17. direction: 'ltr',
  18. };
  19. renderChilren() {
  20. const { direction, children } = this.props;
  21. if (direction === 'rtl') {
  22. return (
  23. <div className={`${BASE_CLASS_PREFIX}-rtl`}>
  24. {children}
  25. </div>
  26. );
  27. }
  28. return children;
  29. }
  30. render() {
  31. const { children, direction, ...rest } = this.props;
  32. return (
  33. <Context.Provider
  34. value={{
  35. direction,
  36. ...rest,
  37. }}
  38. >
  39. {this.renderChilren()}
  40. </Context.Provider>
  41. );
  42. }
  43. }