index.tsx 1.5 KB

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