ant-design/components/button/demo/linear-gradient.tsx
afc163 ce1721b169
demo: improve button gradient demo (#49786)
* demo: improve button gradient demo

* demo: improve button gradient demo
2024-07-09 17:27:16 +08:00

49 lines
1.2 KiB
TypeScript

import React, { useContext } from 'react';
import { Button, ConfigProvider, Space } from 'antd';
import { AntDesignOutlined } from '@ant-design/icons';
import { css } from '@emotion/css';
const App: React.FC = () => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const rootPrefixCls = getPrefixCls();
const linearGradientButton = css`
&.${rootPrefixCls}-btn-primary:not([disabled]):not(.${rootPrefixCls}-btn-dangerous) {
border-width: 0;
> span {
position: relative;
}
&::before {
content: '';
background: linear-gradient(135deg, #6253E1, #04BEFE);
position: absolute;
inset: 0;
opacity: 1;
transition: all 0.3s;
border-radius: inherit;
}
&:hover::before {
opacity: 0;
}
}
`;
return (
<ConfigProvider
button={{
className: linearGradientButton,
}}
>
<Space>
<Button type="primary" size="large" icon={<AntDesignOutlined />}>
Gradient Button
</Button>
<Button size="large">Button</Button>
</Space>
</ConfigProvider>
);
};
export default App;