-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FE] feat: 형광펜 메뉴 및 툴팁 구현 #874
Changes from 16 commits
68438f6
a0b692a
04f04fb
462bb03
d817bdd
f97f414
77f76c2
973daf0
9eb233e
461f270
c1e8346
6228290
52ca34e
cd6d8ec
1ba7d4b
e92c960
a0bc79a
ff817ba
067de8d
54a3be7
cebd3da
1447d44
693e38a
178f3f6
04d1129
733e4bc
aab8168
465b5bc
e36b1ae
8829c36
6a1f189
83e0473
e133509
5127a70
7af6617
043d35b
b124bbc
2842694
ec4db4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { HIGHLIGHT_BUTTON_SIZE } from '@/constants'; | ||
import { Position } from '@/types'; | ||
|
||
export const Button = styled.button<{ $position: Position; $width: number }>` | ||
position: absolute; | ||
top: ${(props) => props.$position.top}; | ||
left: ${(props) => props.$position.left}; | ||
import { HIGHLIGHT_BUTTON_WIDTH } from '@/constants'; | ||
|
||
export const Button = styled.button` | ||
display: flex; | ||
gap: 0.8rem; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
width: ${(props) => `${props.$width / 10}rem`}; | ||
height: ${() => `${HIGHLIGHT_BUTTON_SIZE.height / 10}rem`}; | ||
padding: 0.5rem 0.8rem; | ||
width: ${`${HIGHLIGHT_BUTTON_WIDTH / 10}rem`}; | ||
padding: 0.5rem; | ||
|
||
background-color: ${({ theme }) => theme.colors.white}; | ||
border-radius: ${({ theme }) => theme.borderRadius.basic}; | ||
-webkit-box-shadow: 0 0 ${() => `${HIGHLIGHT_BUTTON_SIZE.shadow / 10}rem`} -0.2rem #343434b8; | ||
box-shadow: 0 0 ${() => `${HIGHLIGHT_BUTTON_SIZE.shadow / 10}rem`} -0.2rem #343434b8; | ||
|
||
&:hover { | ||
background-color: ${({ theme }) => theme.colors.palePurple}; | ||
background-color: ${({ theme }) => theme.colors.lightPurple}; | ||
} | ||
`; | ||
|
||
export const ButtonIcon = styled.img` | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
`; | ||
|
||
export const Color = styled.div` | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
background-color: ${({ theme }) => theme.colors.primary}; | ||
border-radius: 50%; | ||
width: 1.6rem; | ||
height: 1.6rem; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,28 @@ import { useState } from 'react'; | |
import { HIGHLIGHT_SPAN_CLASS_NAME, SYNTAX_BASIC_CLASS_NAME } from '@/constants'; | ||
import { SelectionInfo } from '@/utils'; | ||
|
||
export type HighlightArea = 'full' | 'partial' | 'none'; | ||
|
||
const useCheckHighlight = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 훅이 단순히 형광펜이 쳐진 영역을 리턴하는 게 아니라 형광펜이 쳐진 영역의 범위를 체크하는 훅이라, 이름에 부가적으로 Range 같은 정보가 들어가면 좋겠...지만 지금도 이해하는 데 어려움은 없습니다ㅎㅎ |
||
const [isAddingHighlight, setIsAddingHighlight] = useState(false); | ||
const [highlightArea, setHighlightArea] = useState<HighlightArea>('none'); | ||
|
||
const checkHighlight = (info: SelectionInfo) => { | ||
const selectedAllSpanList = getAllSpanInSelection(info.selection); | ||
const isNoneHighlight = selectedAllSpanList.some((span) => !span.classList.contains(HIGHLIGHT_SPAN_CLASS_NAME)); | ||
let highlightedSpanLength = 0; | ||
|
||
selectedAllSpanList.forEach((span) => { | ||
if (span.classList.contains(HIGHLIGHT_SPAN_CLASS_NAME)) highlightedSpanLength += 1; | ||
}); | ||
|
||
const newHighlightArea: HighlightArea = highlightedSpanLength | ||
? selectedAllSpanList.length === highlightedSpanLength | ||
? 'full' | ||
: 'partial' | ||
: 'none'; | ||
|
||
setIsAddingHighlight(isNoneHighlight); | ||
setHighlightArea(newHighlightArea); | ||
|
||
return isNoneHighlight; | ||
return newHighlightArea; | ||
}; | ||
|
||
const getAllSpanInSelection = (selection: Selection) => { | ||
|
@@ -23,7 +35,7 @@ const useCheckHighlight = () => { | |
}; | ||
|
||
return { | ||
isAddingHighlight, | ||
highlightArea, | ||
checkHighlight, | ||
}; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
뒷북이지만 😅
aria-label
등을 사용하는 대신SR_ONLY
클래스를 별도로 설정한 이유가 궁금해용There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
당시에 접근성에 대한 합의가 이루어지지 않고 구조상 해당 버튼에 대한 설명이 안에 들어있는게 좋지 않나 생각했어서, 별로도 관리하는 방향으로 진행했어요.
지금은 aria-label만으로 충분하다고 생각해 이를 사용하는 것으로 변경되었어요.