Skip to content

Commit

Permalink
separatorをCSSで実装
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Mar 23, 2024
1 parent bec6ffb commit 4aa0357
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions workspaces/app/src/foundation/components/Separator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

import { Color } from '../styles/variables';
Expand All @@ -7,43 +6,15 @@ const _Wrapper = styled.div`
width: 100%;
`;

const _Separator = styled.img`
display: block;
const _Separator = styled.div`
border-top: 1px solid ${Color.MONO_30};
width: 100%;
height: 1px;
`;

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>
<_Separator aria-hidden={true} />
</_Wrapper>
);
};

0 comments on commit 4aa0357

Please sign in to comment.