Skip to content

Commit f99994f

Browse files
github-actions[bot]seungroseungrodotlee
authored
docs(useGeolocation): auto-generated docs (#247)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: seungro <seungro@toss.im> Co-authored-by: seungrodotlee <seungrodotlee@gmail.com>
1 parent be68fd6 commit f99994f

8 files changed

Lines changed: 385 additions & 30 deletions

File tree

.github/workflows/integration.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,63 @@ jobs:
260260
fi
261261
fi
262262
done
263+
264+
verify-exports:
265+
runs-on: ubuntu-latest
266+
steps:
267+
- name: Checkout code
268+
uses: actions/checkout@v4
269+
270+
- name: Check exports
271+
run: |
272+
IMPL_DIRS=("components" "hooks" "utils")
273+
ROOT_INDEX="src/index.ts"
274+
ERROR_LOG=""
275+
HAS_ERROR=0
276+
277+
for dir in "${IMPL_DIRS[@]}"; do
278+
for impl_dir in src/$dir/*/; do
279+
if [ ! -d "$impl_dir" ]; then
280+
continue
281+
fi
282+
283+
impl_name=$(basename "$impl_dir")
284+
impl_index="$impl_dir/index.ts"
285+
impl_file=""
286+
287+
if [ -f "$impl_dir$impl_name.ts" ]; then
288+
impl_file="$impl_name.ts"
289+
elif [ -f "$impl_dir$impl_name.tsx" ]; then
290+
impl_file="$impl_name.tsx"
291+
else
292+
ERROR_LOG+="❌ Implementation file not found for $impl_name\n"
293+
HAS_ERROR=1
294+
continue
295+
fi
296+
297+
if [ ! -f "$impl_index" ]; then
298+
ERROR_LOG+="❌ Missing index.ts in $impl_dir\n"
299+
HAS_ERROR=1
300+
fi
301+
302+
if ! grep -q "export.*from.*['\"]\./$impl_file['\"]" "$impl_index"; then
303+
ERROR_LOG+="❌ $impl_name is not exported in $impl_index\n"
304+
HAS_ERROR=1
305+
fi
306+
307+
relative_path="./$dir/$impl_name/index.ts"
308+
if ! grep -q "export.*from.*['\"]$relative_path['\"]" "$ROOT_INDEX"; then
309+
ERROR_LOG+="❌ $impl_name is not exported in root index.ts\n"
310+
HAS_ERROR=1
311+
fi
312+
done
313+
done
314+
315+
if [ $HAS_ERROR -eq 1 ]; then
316+
echo -e "\n🚨 Export Validation Errors:\n"
317+
echo -e "$ERROR_LOG"
318+
echo -e "\nPlease fix the above export issues."
319+
exit 1
320+
else
321+
echo "✅ All exports are valid!"
322+
fi

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ esm
1111
out
1212
*.d.ts
1313
*.tgz
14+
src/components/**/*.md
15+
src/hooks/**/*.md
16+
src/utils/**/*.md

.scripts/commands/generateDocs/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,15 @@ function getParamUl(param: Spec, nestedParams?: Spec[]) {
286286
}
287287

288288
function replaceDescription(value: string) {
289+
console.log(value);
289290
return value
290291
.replace(/^\s*-\s*/, '')
292+
.replace(/--/g, '\n-')
291293
.replace(/`([^`]*)`/g, '<code>$1</code>')
292294
.replace(/\*\*([^**]*)\*\*/g, '<strong>$1</strong>')
293295
.replace(/\*([^*]*)\*/g, '<em>$1</em>')
294296
.replace(/_([^*]*)_/g, '<em>$1</em>')
295297
.replace(/\n/g, '<br />')
298+
.replace(/'/g, `\\'`)
296299
.replace(/"/g, '&quot;');
297300
}

src/docs/en/contributing.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ JSDoc comments must include `@description` and `@example`, and if there are para
3535
- For required parameters: `@param {<type>} <parameter name> - <parameter description>`
3636
- For optional parameters: `@param {<type>} [<parameter name>] - <parameter description>`
3737
- For object parameters, both the object itself and its properties need `@param` tags.
38+
- If you want to write a list under a description, use `--` instead of `-`.
3839

3940
```ts
4041
type Props = {
@@ -61,6 +62,8 @@ JSDoc comments must include `@description` and `@example`, and if there are para
6162
* @param {Object} [paymentMethod] - Payment information of the user.
6263
* @param {string} [paymentMethod.type] - Payment method.
6364
* @param {string} [paymentMethod.number] - Card or account number.
65+
* -- Card or account number without `-`.
66+
* -- If the number is a card number, it should be 15 or 16 digits.
6467
*/
6568
```
6669

@@ -117,7 +120,7 @@ JSDoc comments must include `@description` and `@example`, and if there are para
117120
{
118121
name: 'paymentMethod.number',
119122
type: 'string',
120-
description: 'Card or account number.',
123+
description: 'Card or account number.<br/>- Card or account number without `-`.<br/>- If the number is a card number, it should be 15 or 16 digits.',
121124
},
122125
]"
123126
/>
@@ -127,13 +130,16 @@ JSDoc comments must include `@description` and `@example`, and if there are para
127130

128131
- Format: `@returns {<type>} <return value description>`
129132
- For object or tuple return values, include descriptions for each member.
133+
- If additional details are needed for each member, please use `:`.
130134

131135
```ts
132-
type ReturnValue = [string, () => void];
136+
type ReturnValue = [Object, () => void];
133137
134138
/**
135-
* @returns {[value: string, onChange: () => void]} A tuple containing:
136-
* - value `string` - The value of the input.
139+
* @returns {[Object, () => void]} A tuple containing:
140+
* - obj `Object` - An object containing:
141+
* : label `string` - The label of the input.
142+
* : value `string` - The value of the input.
137143
* - onChange `() => void` - A function to update the value.
138144
*/
139145
```
@@ -147,9 +153,9 @@ JSDoc comments must include `@description` and `@example`, and if there are para
147153
description="A tuple containing:"
148154
:nested="[
149155
{
150-
name: 'value',
151-
type: 'string',
152-
description: 'The value of the input.',
156+
name: 'obj',
157+
type: 'Object',
158+
description: 'The value of the input. <br /> : label <code>string</code> - The label of the input. <br /> : value <code>string</code> - The value of the input.',
153159
},
154160
{
155161
name: 'onChange',
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# useGeolocation
2+
3+
`useGeolocation`는 사용자의 지리적 위치를 검색하고 추적하는 리액트 훅이에요. 브라우저의 `Geolocation API`를 사용하여 단회 위치 검색과 지속적인 위치 추적을 모두 지원해요.
4+
5+
## Interface
6+
7+
```ts
8+
function useGeolocation(options: GeolocationOptions): Object;
9+
```
10+
11+
### 파라미터
12+
13+
<Interface
14+
name="options"
15+
type="GeolocationOptions"
16+
description="지리적 위치 옵션 설정이에요"
17+
:nested="[
18+
{
19+
name: 'options.mountBehavior',
20+
type: 'GeolocationMountBehaviorType',
21+
required: false,
22+
description:
23+
'훅이 마운트 시 어떻게 동작하는지: <br />- 제공되지 않으면 자동으로 위치를 가져오지 않아요 <br />- \u0027get\u0027: 컴포넌트가 마운트될 때 위치를 자동으로 한 번 가져와요 <br />- \u0027watch\u0027: 컴포넌트가 마운트될 때 위치 변경 추적을 자동으로 시작해요',
24+
},
25+
{
26+
name: 'options.enableHighAccuracy',
27+
type: 'boolean',
28+
required: false,
29+
defaultValue: 'false',
30+
description:
31+
'만약 참이라면, 더 정확한 위치 정보를 제공해요 (배터리 소비 증가)',
32+
},
33+
{
34+
name: 'options.maximumAge',
35+
type: 'number',
36+
required: false,
37+
defaultValue: '0',
38+
description:
39+
'반환이 허용되는 캐시된 위치의 최대 나이(밀리초)예요',
40+
},
41+
{
42+
name: 'options.timeout',
43+
type: 'number',
44+
required: false,
45+
defaultValue: 'Infinity',
46+
description:
47+
'위치를 요청할 때 허용되는 최대 시간(밀리초)예요',
48+
},
49+
]"
50+
/>
51+
52+
### 반환 값
53+
54+
<Interface
55+
name=""
56+
type="Object"
57+
description="위치 데이터와 관련된 함수들을 포함하고 있어요"
58+
:nested="[
59+
{
60+
name: 'loading',
61+
type: 'boolean',
62+
required: false,
63+
description: '현재 위치 데이터를 가져오는 중인지 여부를 나타내요.',
64+
},
65+
{
66+
name: 'error',
67+
type: 'CustomGeoLocationError|null',
68+
required: false,
69+
description:
70+
'오류가 발생했을 때의 오류 객체이거나 null이에요. 이 훅은 표준 Geolocation API 오류 코드(<code>1-3</code>)와 사용자 정의 코드(<code>0</code>)를 사용해요 <br /> : <code>0</code> - 이 환경에서는 지리적 위치가 지원되지 않아요 <br /> : <code>1</code> - 사용자가 지리적 위치 접근 허용을 거부했어요 <br /> : <code>2</code> - 위치를 사용할 수 없어요 <br /> : <code>3</code> - 시간 초과 - 지리적 위치 요청이 너무 오래 걸렸어요.',
71+
},
72+
{
73+
name: 'data',
74+
type: 'GeolocationData|null',
75+
required: false,
76+
description:
77+
'위치 데이터 객체 또는 null이에요 <br /> : 위도 <code>number</code> - 십진수로 표현된 위도예요 <br /> : 경도 <code>number</code> - 십진수로 표현된 경도예요 <br /> : 정확도 <code>number</code> - 위치의 정확도(미터)예요 <br /> : 고도 <code>number|null</code> - WGS84 타원체 기준의 고도(미터)예요 <br /> : 고도 정확도 <code>number|null</code> - 고도의 정확도(미터)예요 <br /> : 방위 <code>number|null</code> - 진북에서 시계방향으로의 방위(도)예요 <br /> : 속도 <code>number|null</code> - 속도(미터/초)예요 <br /> : 타임스탬프 <code>number</code> - 위치가 검색된 시간이에요.',
78+
},
79+
{
80+
name: 'getCurrentPosition',
81+
type: 'Function',
82+
required: false,
83+
description: '현재 위치를 한 번 가져오는 함수에요.',
84+
},
85+
{
86+
name: 'startTracking',
87+
type: 'Function',
88+
required: false,
89+
description: '위치 변경 추적을 시작하는 함수에요.',
90+
},
91+
{
92+
name: 'stopTracking',
93+
type: 'Function',
94+
required: false,
95+
description: '위치 추적을 중지하는 함수에요.',
96+
},
97+
{
98+
name: 'isTracking',
99+
type: 'boolean',
100+
required: false,
101+
description: '현재 위치 추적이 활성화되어 있는지 여부를 나타내요.',
102+
},
103+
]"
104+
/>
105+
106+
## 예시
107+
108+
```tsx
109+
// 기본 사용법
110+
const {
111+
loading,
112+
error,
113+
data,
114+
getCurrentPosition
115+
} = useGeolocation();
116+
117+
// 컴포넌트가 마운트 될 때 자동으로 위치를 가져와요
118+
const {
119+
loading,
120+
error,
121+
data
122+
} = useGeolocation({ mountBehavior: 'get' });
123+
124+
// 위치 추적
125+
const {
126+
loading,
127+
error,
128+
data,
129+
startTracking,
130+
stopTracking,
131+
isTracking
132+
} = useGeolocation();
133+
134+
const handleStartTracking = () => {
135+
startTracking();
136+
};
137+
138+
const handleStopTracking = () => {
139+
stopTracking();
140+
};
141+
```

0 commit comments

Comments
 (0)