dropdownTitle.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { cssClasses } from '@douyinfe/semi-foundation/dropdown/constants';
  4. import cls from 'classnames';
  5. import DropdownContext, { DropdownContextType } from './context';
  6. import { BaseProps } from '../_base/baseComponent';
  7. const prefixCls = cssClasses.PREFIX;
  8. export type DropdownTitleProps = BaseProps;
  9. class DropdownTitle extends PureComponent<DropdownTitleProps> {
  10. static propTypes = {
  11. children: PropTypes.node,
  12. className: PropTypes.string,
  13. style: PropTypes.object,
  14. };
  15. static contextType = DropdownContext;
  16. context: DropdownContextType;
  17. render() {
  18. const { className, style, children } = this.props;
  19. const { showTick } = this.context;
  20. const titleCls = cls({
  21. [`${prefixCls}-title`]: true,
  22. [`${prefixCls}-title-withTick`]: showTick,
  23. }, className);
  24. return (
  25. <div className={titleCls} style={style}>
  26. {children}
  27. </div>
  28. );
  29. }
  30. }
  31. export default DropdownTitle;