Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
232868b9e7 | ||
|
|
8b32fe3994 | ||
|
|
250cbec7b7 | ||
|
|
dfac0db564 | ||
|
|
bb8e6d9d65 | ||
|
|
fd08d7a552 | ||
|
|
6ea2a29a7c |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@cameleer/design-system",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.44",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@cameleer/design-system",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.44",
|
||||
"dependencies": {
|
||||
"lucide-react": "^1.7.0",
|
||||
"react": "^19.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cameleer/design-system",
|
||||
"version": "0.1.41",
|
||||
"version": "0.1.46",
|
||||
"type": "module",
|
||||
"main": "./dist/index.es.js",
|
||||
"module": "./dist/index.es.js",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
.wrapper {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.svg {
|
||||
@@ -78,6 +79,15 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tooltipTime {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 4px;
|
||||
padding-bottom: 3px;
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
}
|
||||
|
||||
.tooltipRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -45,6 +45,7 @@ export function AreaChart({
|
||||
const [tooltip, setTooltip] = useState<{
|
||||
x: number
|
||||
y: number
|
||||
xLabel: string
|
||||
values: { label: string; value: number; color: string }[]
|
||||
} | null>(null)
|
||||
|
||||
@@ -84,6 +85,15 @@ export function AreaChart({
|
||||
|
||||
// Find closest x value
|
||||
const pctX = (mx - dims.paddingLeft) / plotW
|
||||
const firstS = series[0]
|
||||
const idx0 = Math.max(0, Math.min(firstS.data.length - 1, Math.round(pctX * (firstS.data.length - 1))))
|
||||
const xVal = firstS.data[idx0]?.x
|
||||
const xLabel = xVal instanceof Date
|
||||
? xVal.toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||
: typeof xVal === 'number' && xVal > 1e10
|
||||
? new Date(xVal).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||
: String(xVal ?? '')
|
||||
|
||||
const values = series.map((s, i) => {
|
||||
const idx = Math.round(pctX * (s.data.length - 1))
|
||||
const clamped = Math.max(0, Math.min(s.data.length - 1, idx))
|
||||
@@ -95,16 +105,17 @@ export function AreaChart({
|
||||
}
|
||||
})
|
||||
|
||||
setTooltip({ x: mx, y: my, values })
|
||||
setTooltip({ x: mx, y: my, xLabel, values })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
||||
<svg
|
||||
width={width}
|
||||
width="100%"
|
||||
height={height}
|
||||
viewBox={`0 0 ${width} ${height}`}
|
||||
preserveAspectRatio="none"
|
||||
className={styles.svg}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseLeave={() => setTooltip(null)}
|
||||
@@ -223,6 +234,9 @@ export function AreaChart({
|
||||
top: tooltip.y,
|
||||
}}
|
||||
>
|
||||
{tooltip.xLabel && (
|
||||
<div className={styles.tooltipTime}>{tooltip.xLabel}</div>
|
||||
)}
|
||||
{tooltip.values.map((v) => (
|
||||
<div key={v.label} className={styles.tooltipRow}>
|
||||
<span className={styles.tooltipDot} style={{ background: v.color }} />
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
.wrapper {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.svg {
|
||||
|
||||
@@ -101,9 +101,10 @@ export function BarChart({
|
||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
||||
<svg
|
||||
width={width}
|
||||
width="100%"
|
||||
height={height}
|
||||
viewBox={`0 0 ${width} ${height}`}
|
||||
preserveAspectRatio="none"
|
||||
className={styles.svg}
|
||||
onMouseLeave={() => setTooltip(null)}
|
||||
aria-label="Bar chart"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
.wrapper {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.svg {
|
||||
@@ -69,6 +70,15 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tooltipTime {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 4px;
|
||||
padding-bottom: 3px;
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
}
|
||||
|
||||
.tooltipRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -44,6 +44,7 @@ export function LineChart({
|
||||
const [tooltip, setTooltip] = useState<{
|
||||
x: number
|
||||
y: number
|
||||
xLabel: string
|
||||
values: { label: string; value: number; color: string }[]
|
||||
} | null>(null)
|
||||
|
||||
@@ -80,6 +81,15 @@ export function LineChart({
|
||||
const my = e.clientY - rect.top
|
||||
const pctX = (mx - dims.paddingLeft) / plotW
|
||||
|
||||
const firstS = series[0]
|
||||
const idx0 = Math.max(0, Math.min(firstS.data.length - 1, Math.round(pctX * (firstS.data.length - 1))))
|
||||
const xVal = firstS.data[idx0]?.x
|
||||
const xLabel = xVal instanceof Date
|
||||
? xVal.toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||
: typeof xVal === 'number' && xVal > 1e10
|
||||
? new Date(xVal).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||
: String(xVal ?? '')
|
||||
|
||||
const values = series.map((s, i) => {
|
||||
const idx = Math.round(pctX * (s.data.length - 1))
|
||||
const clamped = Math.max(0, Math.min(s.data.length - 1, idx))
|
||||
@@ -91,16 +101,17 @@ export function LineChart({
|
||||
}
|
||||
})
|
||||
|
||||
setTooltip({ x: mx, y: my, values })
|
||||
setTooltip({ x: mx, y: my, xLabel, values })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
||||
<svg
|
||||
width={width}
|
||||
width="100%"
|
||||
height={height}
|
||||
viewBox={`0 0 ${width} ${height}`}
|
||||
preserveAspectRatio="none"
|
||||
className={styles.svg}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseLeave={() => setTooltip(null)}
|
||||
@@ -202,6 +213,9 @@ export function LineChart({
|
||||
className={styles.tooltip}
|
||||
style={{ left: tooltip.x + 12, top: tooltip.y }}
|
||||
>
|
||||
{tooltip.xLabel && (
|
||||
<div className={styles.tooltipTime}>{tooltip.xLabel}</div>
|
||||
)}
|
||||
{tooltip.values.map((v) => (
|
||||
<div key={v.label} className={styles.tooltipRow}>
|
||||
<span className={styles.tooltipDot} style={{ background: v.color }} />
|
||||
|
||||
@@ -81,8 +81,9 @@ export function ToastProvider({ children }: { children: ReactNode }) {
|
||||
const toast = useCallback(
|
||||
(options: ToastOptions): string => {
|
||||
const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
|
||||
const duration = options.duration ?? DEFAULT_DURATION
|
||||
const variant = options.variant ?? 'info'
|
||||
// Error toasts persist until manually dismissed; others auto-close after DEFAULT_DURATION
|
||||
const duration = options.duration ?? (variant === 'error' ? 0 : DEFAULT_DURATION)
|
||||
|
||||
const newToast: ToastItem = {
|
||||
id,
|
||||
@@ -99,11 +100,13 @@ export function ToastProvider({ children }: { children: ReactNode }) {
|
||||
return next.slice(-MAX_TOASTS)
|
||||
})
|
||||
|
||||
// Schedule auto-dismiss
|
||||
const timer = setTimeout(() => {
|
||||
dismiss(id)
|
||||
}, duration)
|
||||
timersRef.current.set(id, timer)
|
||||
// Schedule auto-dismiss (duration 0 = persist until manual dismiss)
|
||||
if (duration > 0) {
|
||||
const timer = setTimeout(() => {
|
||||
dismiss(id)
|
||||
}, duration)
|
||||
timersRef.current.set(id, timer)
|
||||
}
|
||||
|
||||
return id
|
||||
},
|
||||
|
||||
@@ -70,9 +70,10 @@
|
||||
|
||||
.version {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
font-size: 10px;
|
||||
color: var(--sidebar-muted);
|
||||
margin-left: 4px;
|
||||
margin-left: 8px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* Search */
|
||||
|
||||
@@ -155,17 +155,6 @@
|
||||
.env {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 30px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-raised);
|
||||
color: var(--text-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.user {
|
||||
|
||||
64
src/design-system/primitives/FileInput/FileInput.module.css
Normal file
64
src/design-system/primitives/FileInput/FileInput.module.css
Normal file
@@ -0,0 +1,64 @@
|
||||
.wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
border: 1.5px dashed var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-inset);
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
|
||||
.wrap:hover {
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.dragOver {
|
||||
border-color: var(--amber);
|
||||
background: var(--amber-bg);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: var(--text-faint);
|
||||
flex-shrink: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-family: var(--font-body);
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.fileName {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.clearBtn {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 0;
|
||||
transition: color 0.1s, background 0.1s;
|
||||
}
|
||||
|
||||
.clearBtn:hover {
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
99
src/design-system/primitives/FileInput/FileInput.tsx
Normal file
99
src/design-system/primitives/FileInput/FileInput.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import styles from './FileInput.module.css'
|
||||
import { forwardRef, useRef, useState, useImperativeHandle, type ReactNode } from 'react'
|
||||
import { X } from 'lucide-react'
|
||||
|
||||
export interface FileInputProps {
|
||||
/** File type filter, e.g. ".pem,.crt,.cer" */
|
||||
accept?: string
|
||||
/** Icon rendered before the label */
|
||||
icon?: ReactNode
|
||||
/** Placeholder text when no file is selected */
|
||||
placeholder?: string
|
||||
/** Additional CSS class */
|
||||
className?: string
|
||||
/** Called when a file is selected or cleared */
|
||||
onChange?: (file: File | null) => void
|
||||
}
|
||||
|
||||
export interface FileInputHandle {
|
||||
/** The currently selected File, or null */
|
||||
file: File | null
|
||||
/** Programmatically clear the selection */
|
||||
clear: () => void
|
||||
}
|
||||
|
||||
export const FileInput = forwardRef<FileInputHandle, FileInputProps>(
|
||||
({ accept, icon, placeholder = 'Drop file or click to browse', className, onChange }, ref) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [fileName, setFileName] = useState<string | null>(null)
|
||||
const [dragOver, setDragOver] = useState(false)
|
||||
const fileRef = useRef<File | null>(null)
|
||||
|
||||
function select(file: File | null) {
|
||||
fileRef.current = file
|
||||
setFileName(file?.name ?? null)
|
||||
onChange?.(file)
|
||||
}
|
||||
|
||||
function handleInputChange() {
|
||||
select(inputRef.current?.files?.[0] ?? null)
|
||||
}
|
||||
|
||||
function handleDrop(e: React.DragEvent) {
|
||||
e.preventDefault()
|
||||
setDragOver(false)
|
||||
const file = e.dataTransfer.files[0]
|
||||
if (file && inputRef.current) {
|
||||
const dt = new DataTransfer()
|
||||
dt.items.add(file)
|
||||
inputRef.current.files = dt.files
|
||||
select(file)
|
||||
}
|
||||
}
|
||||
|
||||
function handleClear(e: React.MouseEvent) {
|
||||
e.stopPropagation()
|
||||
if (inputRef.current) inputRef.current.value = ''
|
||||
select(null)
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
get file() { return fileRef.current },
|
||||
clear() {
|
||||
if (inputRef.current) inputRef.current.value = ''
|
||||
select(null)
|
||||
},
|
||||
}))
|
||||
|
||||
const wrapClass = [styles.wrap, dragOver && styles.dragOver, className].filter(Boolean).join(' ')
|
||||
|
||||
return (
|
||||
<div
|
||||
className={wrapClass}
|
||||
onClick={() => inputRef.current?.click()}
|
||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true) }}
|
||||
onDragLeave={() => setDragOver(false)}
|
||||
onDrop={handleDrop}
|
||||
>
|
||||
{icon && <span className={styles.icon}>{icon}</span>}
|
||||
<span className={`${styles.label} ${fileName ? styles.fileName : styles.placeholder}`}>
|
||||
{fileName ?? placeholder}
|
||||
</span>
|
||||
{fileName && (
|
||||
<button type="button" className={styles.clearBtn} onClick={handleClear} aria-label="Clear file">
|
||||
<X size={12} />
|
||||
</button>
|
||||
)}
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept={accept}
|
||||
onChange={handleInputChange}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
FileInput.displayName = 'FileInput'
|
||||
@@ -11,6 +11,8 @@ export { Collapsible } from './Collapsible/Collapsible'
|
||||
export { DateRangePicker } from './DateRangePicker/DateRangePicker'
|
||||
export { DateTimePicker } from './DateTimePicker/DateTimePicker'
|
||||
export { EmptyState } from './EmptyState/EmptyState'
|
||||
export { FileInput } from './FileInput/FileInput'
|
||||
export type { FileInputProps, FileInputHandle } from './FileInput/FileInput'
|
||||
export { FilterPill } from './FilterPill/FilterPill'
|
||||
export { FormField } from './FormField/FormField'
|
||||
export { InfoCallout } from './InfoCallout/InfoCallout'
|
||||
|
||||
Reference in New Issue
Block a user