Skip to content

Commit

Permalink
Separatorをただのdivに書き換え
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Mar 23, 2024
1 parent 56b8a9d commit 179c83f
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions workspaces/app/src/foundation/components/Separator.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
import { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

import { Color } from '../styles/variables';

const _Wrapper = styled.div`
width: 100%;
`;

const _Separator = styled.img`
display: block;
width: 100%;
export const Separator = styled.div`
background-color: ${Color.MONO_30};
height: 1px;
width: 100%;
`;

export const Separator: React.FC = () => {
const wrapperRef = useRef<HTMLDivElement>(null);
const [imgUrl, setImgUrl] = useState<string | null>(null);

useEffect(() => {
const width = wrapperRef.current?.clientWidth;

const canvas = document.createElement('canvas');
canvas.width = width ?? 0;
canvas.height = 1;

const ctx = canvas.getContext('2d');

if (ctx == null) {
return;
}

ctx.moveTo(0, 0);
ctx.lineTo(width ?? 0, 0);

ctx.strokeStyle = Color.MONO_30;
ctx.lineWidth = 1;

ctx.stroke();

setImgUrl(canvas.toDataURL('image/png'));
}, []);

return (
<_Wrapper ref={wrapperRef}>
{imgUrl != null ? <_Separator aria-hidden={true} height={1} src={imgUrl} width="100%" /> : null}
</_Wrapper>
);
};

0 comments on commit 179c83f

Please sign in to comment.