diff --git a/components/empty/__tests__/index.test.tsx b/components/empty/__tests__/index.test.tsx index ade004ab19..0f466298dc 100644 --- a/components/empty/__tests__/index.test.tsx +++ b/components/empty/__tests__/index.test.tsx @@ -4,6 +4,7 @@ import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; +import theme from '../../theme'; describe('Empty', () => { mountTest(Empty); @@ -27,4 +28,20 @@ describe('Empty', () => { ); expect(asFragment().firstChild).toMatchSnapshot(); }); + + it('dark mode compatible', () => { + const { container } = render( + + + , + ); + + expect(container.querySelector('svg')).toHaveStyle({ + opacity: 0.65, + }); + }); }); diff --git a/components/empty/empty.tsx b/components/empty/empty.tsx index 7084fef3c6..2ed60950b2 100644 --- a/components/empty/empty.tsx +++ b/components/empty/empty.tsx @@ -1,38 +1,71 @@ +import { TinyColor } from '@ctrl/tinycolor'; import * as React from 'react'; +import { useToken } from '../theme/internal'; -const Empty = () => ( - - - - +const Empty = () => { + const [, token] = useToken(); + + const bgColor = new TinyColor(token.colorBgBase); + let themeStyle: React.CSSProperties = {}; + + // Dark Theme need more dark of this + if (bgColor.toHsl().l < 0.5) { + themeStyle = { + opacity: 0.65, + }; + } + + return ( + + + + + + + + + - - - + + + + - - - - - - - -); + + ); +}; + +if (process.env.NODE_ENV !== 'production') { + Empty.displayName = 'EmptyImage'; +} export default Empty;