@kids-reporter/routing-ui 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +17 -0
- package/babel.config.cjs +31 -0
- package/dist/components/button.d.ts +23 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +82 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +21 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/input.d.ts +20 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +143 -0
- package/dist/components/input.js.map +1 -0
- package/dist/constants/default-values.d.ts +12 -0
- package/dist/constants/default-values.d.ts.map +1 -0
- package/dist/constants/default-values.js +148 -0
- package/dist/constants/default-values.js.map +1 -0
- package/dist/footer.d.ts +10 -0
- package/dist/footer.d.ts.map +1 -0
- package/dist/footer.js +144 -0
- package/dist/footer.js.map +1 -0
- package/dist/header/desktop-header.d.ts +14 -0
- package/dist/header/desktop-header.d.ts.map +1 -0
- package/dist/header/desktop-header.js +85 -0
- package/dist/header/desktop-header.js.map +1 -0
- package/dist/header/header-context.d.ts +16 -0
- package/dist/header/header-context.d.ts.map +1 -0
- package/dist/header/header-context.js +37 -0
- package/dist/header/header-context.js.map +1 -0
- package/dist/header/index.d.ts +12 -0
- package/dist/header/index.d.ts.map +1 -0
- package/dist/header/index.js +72 -0
- package/dist/header/index.js.map +1 -0
- package/dist/header/menu/header-menu-item-group.d.ts +7 -0
- package/dist/header/menu/header-menu-item-group.d.ts.map +1 -0
- package/dist/header/menu/header-menu-item-group.js +31 -0
- package/dist/header/menu/header-menu-item-group.js.map +1 -0
- package/dist/header/menu/header-menu-item.d.ts +9 -0
- package/dist/header/menu/header-menu-item.d.ts.map +1 -0
- package/dist/header/menu/header-menu-item.js +92 -0
- package/dist/header/menu/header-menu-item.js.map +1 -0
- package/dist/header/menu/index.d.ts +15 -0
- package/dist/header/menu/index.d.ts.map +1 -0
- package/dist/header/menu/index.js +170 -0
- package/dist/header/menu/index.js.map +1 -0
- package/dist/header/mobile-header.d.ts +9 -0
- package/dist/header/mobile-header.d.ts.map +1 -0
- package/dist/header/mobile-header.js +46 -0
- package/dist/header/mobile-header.js.map +1 -0
- package/dist/header/post-title-setter.d.ts +6 -0
- package/dist/header/post-title-setter.d.ts.map +1 -0
- package/dist/header/post-title-setter.js +22 -0
- package/dist/header/post-title-setter.js.map +1 -0
- package/dist/header/shared-components.d.ts +31 -0
- package/dist/header/shared-components.d.ts.map +1 -0
- package/dist/header/shared-components.js +256 -0
- package/dist/header/shared-components.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-is-at-top.d.ts +3 -0
- package/dist/hooks/use-is-at-top.d.ts.map +1 -0
- package/dist/hooks/use-is-at-top.js +26 -0
- package/dist/hooks/use-is-at-top.js.map +1 -0
- package/dist/hooks/use-media-query.d.ts +7 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +47 -0
- package/dist/hooks/use-media-query.js.map +1 -0
- package/dist/hooks/use-scroll-level.d.ts +11 -0
- package/dist/hooks/use-scroll-level.d.ts.map +1 -0
- package/dist/hooks/use-scroll-level.js +53 -0
- package/dist/hooks/use-scroll-level.js.map +1 -0
- package/dist/icons/index.d.ts +17 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +341 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +101 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +475 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/cn.d.ts +8 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +27 -0
- package/dist/utils/cn.js.map +1 -0
- package/dist/utils/generate-social-media-config.d.ts +9 -0
- package/dist/utils/generate-social-media-config.d.ts.map +1 -0
- package/dist/utils/generate-social-media-config.js +55 -0
- package/dist/utils/generate-social-media-config.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +28 -0
- package/dist/utils/index.js.map +1 -0
- package/eslint.config.mjs +55 -0
- package/package.json +51 -0
- package/prettier.config.mjs +13 -0
- package/scripts/build.sh +18 -0
- package/src/components/button.tsx +108 -0
- package/src/components/index.tsx +2 -0
- package/src/components/input.tsx +171 -0
- package/src/constants/default-values.tsx +153 -0
- package/src/footer.tsx +151 -0
- package/src/header/desktop-header.tsx +128 -0
- package/src/header/header-context.tsx +56 -0
- package/src/header/index.tsx +96 -0
- package/src/header/menu/header-menu-item-group.tsx +37 -0
- package/src/header/menu/header-menu-item.tsx +132 -0
- package/src/header/menu/index.tsx +206 -0
- package/src/header/mobile-header.tsx +61 -0
- package/src/header/post-title-setter.tsx +22 -0
- package/src/header/shared-components.tsx +326 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-is-at-top.ts +23 -0
- package/src/hooks/use-media-query.ts +57 -0
- package/src/hooks/use-scroll-level.ts +52 -0
- package/src/icons/index.tsx +358 -0
- package/src/index.ts +9 -0
- package/src/styles.css +475 -0
- package/src/types/index.ts +10 -0
- package/src/utils/cn.ts +41 -0
- package/src/utils/generate-social-media-config.ts +75 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import baseConfig, {
|
|
2
|
+
typescriptConfig,
|
|
3
|
+
javascriptConfig,
|
|
4
|
+
} from '../../eslint.base.config.mjs'
|
|
5
|
+
import globals from 'globals'
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
...baseConfig,
|
|
9
|
+
// Override for routing-ui package - React/TypeScript focused
|
|
10
|
+
{
|
|
11
|
+
...typescriptConfig,
|
|
12
|
+
files: ['src/**/*.{ts,tsx}'],
|
|
13
|
+
rules: {
|
|
14
|
+
...typescriptConfig.rules,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
...javascriptConfig,
|
|
19
|
+
files: ['src/**/*.{js,jsx}'],
|
|
20
|
+
rules: {
|
|
21
|
+
...javascriptConfig.rules,
|
|
22
|
+
// Tailwind CSS classname sorting rules
|
|
23
|
+
'no-restricted-syntax': [
|
|
24
|
+
'warn',
|
|
25
|
+
{
|
|
26
|
+
selector: 'JSXAttribute[name.name="className"]',
|
|
27
|
+
message:
|
|
28
|
+
'Tailwind CSS classes should be sorted. Use prettier-plugin-tailwindcss for automatic sorting.',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
selector: 'JSXAttribute[name.name="class"]',
|
|
32
|
+
message:
|
|
33
|
+
'CSS classes should be sorted. Consider using a class sorting tool.',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
files: ['**/*.config.{js,mjs,cjs}'],
|
|
40
|
+
languageOptions: {
|
|
41
|
+
ecmaVersion: 2022,
|
|
42
|
+
sourceType: 'module',
|
|
43
|
+
globals: {
|
|
44
|
+
...globals.node,
|
|
45
|
+
...globals.es2022,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
'no-undef': 'error',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
ignores: ['node_modules/**', 'dist/**', 'build/**'],
|
|
54
|
+
},
|
|
55
|
+
]
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kids-reporter/routing-ui",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "0.1.0-alpha.1",
|
|
5
|
+
"description": "Routing UI for Kids Reporter",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./styles.css": "./dist/styles.css"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "./scripts/build.sh",
|
|
19
|
+
"lint": "eslint . --config ./eslint.config.mjs",
|
|
20
|
+
"lint:check": "eslint . --config ./eslint.config.mjs",
|
|
21
|
+
"type-check": "tsc --noEmit",
|
|
22
|
+
"postinstall": "yarn build"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@radix-ui/react-slot": "^1.2.3",
|
|
26
|
+
"class-variance-authority": "^0.7.1",
|
|
27
|
+
"clsx": "^2.1.1",
|
|
28
|
+
"lodash": "^4.17.21",
|
|
29
|
+
"tailwind-merge": "^3.3.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@babel/cli": "^7.17.10",
|
|
33
|
+
"@babel/core": "^7.18.5",
|
|
34
|
+
"@babel/plugin-transform-runtime": "^7.18.5",
|
|
35
|
+
"@babel/preset-env": "^7.18.2",
|
|
36
|
+
"@babel/preset-react": "^7.17.12",
|
|
37
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
38
|
+
"@babel/runtime": "^7.18.5",
|
|
39
|
+
"@types/lodash": "^4.17.7",
|
|
40
|
+
"@types/react": "^18.3.7",
|
|
41
|
+
"@types/react-dom": "18.3.7",
|
|
42
|
+
"prettier": "^3.6.2",
|
|
43
|
+
"prettier-plugin-tailwindcss": "^0.6.14",
|
|
44
|
+
"typescript": "^5.9.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "18.3.1",
|
|
48
|
+
"react-dom": "18.3.1",
|
|
49
|
+
"tailwindcss": "^4.1.14"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
|
|
2
|
+
export default {
|
|
3
|
+
printWidth: 80,
|
|
4
|
+
tabWidth: 2,
|
|
5
|
+
semi: false,
|
|
6
|
+
singleQuote: true,
|
|
7
|
+
trailingComma: 'es5',
|
|
8
|
+
bracketSpacing: true,
|
|
9
|
+
arrowParens: 'always',
|
|
10
|
+
plugins: ['prettier-plugin-tailwindcss'],
|
|
11
|
+
tailwindStylesheet: './src/styles.css',
|
|
12
|
+
tailwindFunctions: ['clsx', 'cn', 'cva'],
|
|
13
|
+
}
|
package/scripts/build.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
echo "Cleaning dist directory..."
|
|
6
|
+
rm -rf ./dist
|
|
7
|
+
mkdir -p ./dist
|
|
8
|
+
|
|
9
|
+
echo "Building CJS version..."
|
|
10
|
+
npx babel src --out-dir dist --extensions ".ts,.tsx" --source-maps
|
|
11
|
+
|
|
12
|
+
echo "Copying CSS file..."
|
|
13
|
+
cp ./src/styles.css ./dist/styles.css
|
|
14
|
+
|
|
15
|
+
echo "Generating TypeScript declarations..."
|
|
16
|
+
npx tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist
|
|
17
|
+
|
|
18
|
+
echo "Build completed successfully!"
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '../utils/cn'
|
|
8
|
+
|
|
9
|
+
const buttonVariants = cva(
|
|
10
|
+
// Base styles
|
|
11
|
+
'font-noto gap-2.5 font-bold inline-flex cursor-pointer items-center justify-center rounded-full transition-colors duration-200',
|
|
12
|
+
{
|
|
13
|
+
variants: {
|
|
14
|
+
variant: {
|
|
15
|
+
primary: [
|
|
16
|
+
'text-white border-0 bg-red-400',
|
|
17
|
+
'hover:bg-red-500',
|
|
18
|
+
'active:bg-red-600',
|
|
19
|
+
'disabled:bg-gray-400 disabled:text-white disabled:cursor-default',
|
|
20
|
+
],
|
|
21
|
+
secondary: [
|
|
22
|
+
'bg-white text-gray-900 border-2 border-red-400',
|
|
23
|
+
'hover:text-white hover:border-red-500 hover:bg-red-500',
|
|
24
|
+
'active:text-white active:border-red-600 active:bg-red-600',
|
|
25
|
+
'disabled:border-gray-400 disabled:bg-white disabled:text-gray-400 disabled:cursor-default',
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
size: {
|
|
29
|
+
44: 'h-11 px-5 py-2 text-base', // 44px height, 16px font size
|
|
30
|
+
36: 'h-9 px-4 py-2 text-sm', // 36px height, 14px font size
|
|
31
|
+
32: 'h-8 px-3 py-1 text-sm', // 32px height, 14px font size
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: 'primary',
|
|
36
|
+
size: 44,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// Loading spinner icon component
|
|
42
|
+
const LoadingSpinner = ({ size = 20 }: { size?: number }) => (
|
|
43
|
+
<svg
|
|
44
|
+
width={size}
|
|
45
|
+
height={size}
|
|
46
|
+
viewBox="0 0 25 24"
|
|
47
|
+
fill="none"
|
|
48
|
+
className="animate-spin"
|
|
49
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
50
|
+
>
|
|
51
|
+
<path
|
|
52
|
+
opacity="0.5"
|
|
53
|
+
d="M12.5 2C10.5222 2 8.58879 2.58649 6.9443 3.6853C5.29981 4.78412 4.01809 6.3459 3.26121 8.17317C2.50433 10.0004 2.3063 12.0111 2.69215 13.9509C3.078 15.8907 4.03041 17.6725 5.42894 19.0711C6.82746 20.4696 8.60929 21.422 10.5491 21.8079C12.4889 22.1937 14.4996 21.9957 16.3268 21.2388C18.1541 20.4819 19.7159 19.2002 20.8147 17.5557C21.9135 15.9112 22.5 13.9778 22.5 12C22.5 10.6868 22.2413 9.38642 21.7388 8.17317C21.2363 6.95991 20.4997 5.85752 19.5711 4.92893C18.6425 4.00035 17.5401 3.26375 16.3268 2.7612C15.1136 2.25866 13.8132 2 12.5 2ZM12.5 20C10.9178 20 9.37104 19.5308 8.05544 18.6518C6.73985 17.7727 5.71447 16.5233 5.10897 15.0615C4.50347 13.5997 4.34504 11.9911 4.65372 10.4393C4.9624 8.88743 5.72433 7.46197 6.84315 6.34315C7.96197 5.22433 9.38743 4.4624 10.9393 4.15372C12.4911 3.84504 14.0997 4.00346 15.5615 4.60896C17.0233 5.21447 18.2727 6.23984 19.1518 7.55544C20.0308 8.87103 20.5 10.4177 20.5 12C20.5 14.1217 19.6572 16.1566 18.1569 17.6569C16.6566 19.1571 14.6217 20 12.5 20Z"
|
|
54
|
+
fill="currentColor"
|
|
55
|
+
/>
|
|
56
|
+
<path
|
|
57
|
+
d="M20.5 12H22.5C22.5 10.6868 22.2413 9.38642 21.7388 8.17317C21.2362 6.95991 20.4997 5.85752 19.5711 4.92893C18.6425 4.00035 17.5401 3.26375 16.3268 2.7612C15.1136 2.25866 13.8132 2 12.5 2V4C14.6217 4 16.6566 4.84285 18.1569 6.34315C19.6571 7.84344 20.5 9.87827 20.5 12Z"
|
|
58
|
+
fill="currentColor"
|
|
59
|
+
/>
|
|
60
|
+
</svg>
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export type ButtonProps = {
|
|
64
|
+
isLoading?: boolean
|
|
65
|
+
disabled?: boolean
|
|
66
|
+
asChild?: boolean
|
|
67
|
+
children: React.ReactNode
|
|
68
|
+
} & VariantProps<typeof buttonVariants> &
|
|
69
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
70
|
+
|
|
71
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
72
|
+
(
|
|
73
|
+
{
|
|
74
|
+
isLoading = false,
|
|
75
|
+
disabled = false,
|
|
76
|
+
asChild = false,
|
|
77
|
+
size,
|
|
78
|
+
variant,
|
|
79
|
+
className,
|
|
80
|
+
children,
|
|
81
|
+
...props
|
|
82
|
+
},
|
|
83
|
+
ref
|
|
84
|
+
) => {
|
|
85
|
+
const isDisabled = disabled || isLoading
|
|
86
|
+
|
|
87
|
+
const buttonClasses = cn(buttonVariants({ variant, size }), className)
|
|
88
|
+
|
|
89
|
+
const Comp = asChild ? Slot : 'button'
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Comp
|
|
93
|
+
ref={ref}
|
|
94
|
+
className={buttonClasses}
|
|
95
|
+
disabled={isDisabled}
|
|
96
|
+
{...props}
|
|
97
|
+
>
|
|
98
|
+
{isLoading ? (
|
|
99
|
+
<LoadingSpinner size={size === 32 ? 16 : size === 36 ? 18 : 20} />
|
|
100
|
+
) : (
|
|
101
|
+
children
|
|
102
|
+
)}
|
|
103
|
+
</Comp>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
export default Button
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { cva } from 'class-variance-authority'
|
|
4
|
+
import { forwardRef, useRef, useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { SearchIconSmall } from '../icons'
|
|
7
|
+
import { cn } from '../utils/cn'
|
|
8
|
+
|
|
9
|
+
// Close icon component
|
|
10
|
+
const CloseIcon = ({ className }: { className?: string }) => (
|
|
11
|
+
<svg
|
|
12
|
+
width="20"
|
|
13
|
+
height="20"
|
|
14
|
+
viewBox="0 0 20 20"
|
|
15
|
+
fill="none"
|
|
16
|
+
className={className}
|
|
17
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
18
|
+
>
|
|
19
|
+
<circle cx="10" cy="10" r="10" fill="currentColor" />
|
|
20
|
+
<path
|
|
21
|
+
d="M7 7l6 6M13 7l-6 6"
|
|
22
|
+
stroke="white"
|
|
23
|
+
strokeWidth="1.5"
|
|
24
|
+
strokeLinecap="round"
|
|
25
|
+
strokeLinejoin="round"
|
|
26
|
+
/>
|
|
27
|
+
</svg>
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const inputVariants = cva(
|
|
31
|
+
// Base styles
|
|
32
|
+
'prose-p1 desktop:bg-white! px-4 py-1.5 h-11 flex items-center rounded-full border border-transparent bg-neutral-100 transition-colors duration-200 hover:border-neutral-600',
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
state: {
|
|
36
|
+
default: 'border-transparent',
|
|
37
|
+
hover: 'border-neutral-600',
|
|
38
|
+
focus: 'border-neutral-600',
|
|
39
|
+
active: 'border-neutral-600',
|
|
40
|
+
unfocus: 'border-transparent',
|
|
41
|
+
error: 'border-red-600',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
state: 'default',
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
export type InputProps = {
|
|
51
|
+
placeholder?: string
|
|
52
|
+
value?: string
|
|
53
|
+
onChange?: (value: string) => void
|
|
54
|
+
onClear?: () => void
|
|
55
|
+
showClearButton?: boolean
|
|
56
|
+
children?: React.ReactNode
|
|
57
|
+
inputRef?: React.RefObject<HTMLInputElement>
|
|
58
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value'>
|
|
59
|
+
|
|
60
|
+
const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
61
|
+
(
|
|
62
|
+
{
|
|
63
|
+
placeholder = '搜尋更多新聞、議題',
|
|
64
|
+
value,
|
|
65
|
+
onChange,
|
|
66
|
+
onClear,
|
|
67
|
+
showClearButton = true,
|
|
68
|
+
className,
|
|
69
|
+
onFocus,
|
|
70
|
+
onBlur,
|
|
71
|
+
inputRef,
|
|
72
|
+
...props
|
|
73
|
+
},
|
|
74
|
+
ref
|
|
75
|
+
) => {
|
|
76
|
+
const [internalValue, setInternalValue] = useState('')
|
|
77
|
+
const [isFocused, setIsFocused] = useState(false)
|
|
78
|
+
const [isActive, setIsActive] = useState(false)
|
|
79
|
+
const innerInputRef = useRef<HTMLInputElement>(null)
|
|
80
|
+
const currentValue = value !== undefined ? value : internalValue
|
|
81
|
+
const hasValue = currentValue.length > 0
|
|
82
|
+
|
|
83
|
+
// Determine current state
|
|
84
|
+
const currentState = isFocused
|
|
85
|
+
? 'focus'
|
|
86
|
+
: hasValue
|
|
87
|
+
? isActive
|
|
88
|
+
? 'active'
|
|
89
|
+
: 'unfocus'
|
|
90
|
+
: 'default'
|
|
91
|
+
|
|
92
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
93
|
+
const newValue = e.target.value
|
|
94
|
+
if (onChange) {
|
|
95
|
+
onChange(newValue)
|
|
96
|
+
} else {
|
|
97
|
+
setInternalValue(newValue)
|
|
98
|
+
}
|
|
99
|
+
setIsActive(true)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
103
|
+
if (onFocus) {
|
|
104
|
+
onFocus(e)
|
|
105
|
+
}
|
|
106
|
+
setIsFocused(true)
|
|
107
|
+
setIsActive(true)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
111
|
+
if (onBlur) {
|
|
112
|
+
onBlur(e)
|
|
113
|
+
}
|
|
114
|
+
setIsFocused(false)
|
|
115
|
+
setIsActive(false)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const handleClear = (e: React.MouseEvent) => {
|
|
119
|
+
e.preventDefault()
|
|
120
|
+
e.stopPropagation()
|
|
121
|
+
|
|
122
|
+
if (onChange) {
|
|
123
|
+
onChange('')
|
|
124
|
+
} else {
|
|
125
|
+
setInternalValue('')
|
|
126
|
+
}
|
|
127
|
+
if (onClear) {
|
|
128
|
+
onClear()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const currentRef = inputRef ?? innerInputRef
|
|
132
|
+
currentRef.current?.focus()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const inputClasses = cn(inputVariants({ state: currentState }), className)
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div className="gap-2 flex flex-col">
|
|
139
|
+
<div className={inputClasses} ref={ref}>
|
|
140
|
+
<div className="text-neutral-600">
|
|
141
|
+
<SearchIconSmall />
|
|
142
|
+
</div>
|
|
143
|
+
<input
|
|
144
|
+
type="text"
|
|
145
|
+
value={currentValue}
|
|
146
|
+
onChange={handleChange}
|
|
147
|
+
onFocus={handleFocus}
|
|
148
|
+
onBlur={handleBlur}
|
|
149
|
+
placeholder={placeholder}
|
|
150
|
+
className="placeholder:font-medium ml-2 max-w-[72%] flex-1 flex-shrink-1 bg-transparent text-neutral-900 placeholder:text-neutral-400 focus:outline-none"
|
|
151
|
+
ref={inputRef ?? innerInputRef}
|
|
152
|
+
{...props}
|
|
153
|
+
/>
|
|
154
|
+
|
|
155
|
+
{showClearButton && hasValue && (
|
|
156
|
+
<button
|
|
157
|
+
type="button"
|
|
158
|
+
onClick={handleClear}
|
|
159
|
+
className="p-1/2 ml-auto flex-shrink-0 cursor-pointer rounded-full text-neutral-400 transition-colors hover:text-neutral-600 active:bg-neutral-200"
|
|
160
|
+
aria-label="Clear input"
|
|
161
|
+
>
|
|
162
|
+
<CloseIcon />
|
|
163
|
+
</button>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
export default Input
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { SettingsIconSmall } from '../icons'
|
|
2
|
+
import { MenuItem } from '../types'
|
|
3
|
+
|
|
4
|
+
export const SUBSCRIBE_URL = 'https://solink.soundon.fm/kidstwreporter'
|
|
5
|
+
export const DONATE_URL = 'https://support.twreporter.org/'
|
|
6
|
+
export const PRIVACY_POLICY = 'https://www.twreporter.org/a/privacy-policy'
|
|
7
|
+
export const SEARCH_PLACEHOLDER = '搜尋更多新聞、議題'
|
|
8
|
+
|
|
9
|
+
export const MENU_ITEMS: MenuItem[] = [
|
|
10
|
+
{
|
|
11
|
+
label: '最新',
|
|
12
|
+
href: '/all',
|
|
13
|
+
subItems: [],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: '專題',
|
|
17
|
+
href: '/topic/page',
|
|
18
|
+
subItems: [],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: '新聞',
|
|
22
|
+
href: '/category/news',
|
|
23
|
+
subItems: [
|
|
24
|
+
{ label: '焦點新聞', href: '/category/news/times' },
|
|
25
|
+
{ label: '真的假的', href: '/category/news/knowledge' },
|
|
26
|
+
{ label: '人物故事', href: '/category/news/story' },
|
|
27
|
+
{ label: '文化報導', href: '/category/news/explore' },
|
|
28
|
+
{ label: '專欄', href: '/category/news/column' },
|
|
29
|
+
{ label: '英文新聞', href: '/categories/news/english-version' },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: '多媒體',
|
|
34
|
+
href: '/category/comics',
|
|
35
|
+
subItems: [
|
|
36
|
+
{ label: '圖解新聞', href: '/category/comics/times' },
|
|
37
|
+
{ label: '新聞遊戲', href: '/category/comics/test-news' },
|
|
38
|
+
{ label: '圖文故事', href: '/category/comics/graphic-story' },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: '校園',
|
|
43
|
+
href: '/category/campus/news-classroom',
|
|
44
|
+
subItems: [
|
|
45
|
+
{ label: '校園寶可夢', href: '/category/campus/campus-pokemon' },
|
|
46
|
+
{ label: '上課好好玩', href: '/category/campus/teaching' },
|
|
47
|
+
{ label: '小讀者連線', href: '/category/campus/joining' },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
label: 'Podcast',
|
|
52
|
+
href: '/category/listening-news',
|
|
53
|
+
subItems: [
|
|
54
|
+
{
|
|
55
|
+
label: '小記者,問什麼?',
|
|
56
|
+
href: '/category/listening-news/kids-reporter-ask',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
label: '新聞讀報',
|
|
60
|
+
href: '/category/listening-news/multilingual-listening-news',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
label: '新聞關鍵字',
|
|
64
|
+
href: '/category/listening-news/listening-news-keywords',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: '文化關鍵字',
|
|
68
|
+
href: '/category/listening-news/listening-news-culture-keywords',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: '教案',
|
|
74
|
+
href: '/category/classroom',
|
|
75
|
+
subItems: [],
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
export const ADDITIONAL_MENU_ITEMS: MenuItem[] = [
|
|
80
|
+
{
|
|
81
|
+
label: '閱讀探索設定',
|
|
82
|
+
href: '/reading-settings',
|
|
83
|
+
subItems: [],
|
|
84
|
+
showIcon: true,
|
|
85
|
+
icon: <SettingsIconSmall />,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: '關於我們',
|
|
89
|
+
href: '/about',
|
|
90
|
+
subItems: [],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: '呼叫報導仔流程',
|
|
94
|
+
href: '/about#callkidsreporter',
|
|
95
|
+
subItems: [],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: '投稿專區',
|
|
99
|
+
href: 'https://forms.gle/49AEG8kFj7QWjgij8',
|
|
100
|
+
subItems: [],
|
|
101
|
+
external: true,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
label: '加入小記者',
|
|
105
|
+
href: 'https://forms.gle/eGq5jagNTwriwSCX6',
|
|
106
|
+
subItems: [],
|
|
107
|
+
external: true,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
label: '訂閱Podcast',
|
|
111
|
+
href: 'https://solink.soundon.fm/kidstwreporter',
|
|
112
|
+
subItems: [],
|
|
113
|
+
external: true,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
label: '聯絡我們',
|
|
117
|
+
href: '/about#mail',
|
|
118
|
+
subItems: [],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
label: '前往《報導者》',
|
|
122
|
+
href: 'https://www.twreporter.org/',
|
|
123
|
+
subItems: [],
|
|
124
|
+
external: true,
|
|
125
|
+
},
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
export const SOCIAL_MEDIA_ITEMS = [
|
|
129
|
+
{
|
|
130
|
+
label: 'Facebook',
|
|
131
|
+
href: 'https://www.facebook.com/twreporter/',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
label: 'Instagram',
|
|
135
|
+
href: 'https://www.instagram.com/twreporter/',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
label: 'YouTube',
|
|
139
|
+
href: 'https://www.youtube.com/@TwreporterOrg',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
label: 'Threads',
|
|
143
|
+
href: 'https://www.threads.com/@twreporter',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
label: 'Medium',
|
|
147
|
+
href: 'https://medium.com/twreporter',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
label: 'RSS',
|
|
151
|
+
href: 'https://kids-storage.twreporter.org/rss/rss.xml',
|
|
152
|
+
},
|
|
153
|
+
]
|