ant-design/.dumi/theme/builtins/Audio/index.tsx

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-09-26 14:02:10 +08:00
import React from 'react';
import { SoundOutlined } from '@ant-design/icons';
import { createStyles } from 'antd-style';
2024-09-26 14:02:10 +08:00
const useStyle = createStyles(({ css, token }) => {
const { paddingXXS, fontSizeXL, motionDurationSlow, colorLink, colorLinkHover, colorLinkActive } =
token;
return {
playBtn: css`
display: inline-flex;
justify-content: center;
align-items: center;
column-gap: ${paddingXXS}px;
margin: 0;
`,
icon: css`
font-size: ${fontSizeXL}px;
color: ${colorLink};
transition: all ${motionDurationSlow};
&:hover {
color: ${colorLinkHover};
}
&:active {
color: ${colorLinkActive};
}
`,
};
});
interface AudioProps {
id?: string;
}
const AudioControl: React.FC<React.PropsWithChildren<AudioProps>> = ({ id, children }) => {
const { styles } = useStyle();
const onClick: React.MouseEventHandler<HTMLAnchorElement> = () => {
const audio = document.querySelector<HTMLAudioElement>(`#${id}`);
audio?.play();
};
2024-09-26 14:02:10 +08:00
return (
<a className={styles.playBtn} onClick={onClick}>
2024-09-26 14:02:10 +08:00
{children}
<SoundOutlined className={styles.icon} />
2024-09-26 14:02:10 +08:00
</a>
);
};
export default AudioControl;