File size: 8,314 Bytes
65d68f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
"use client";

import Link from "next/link";
import { HTMLAttributes } from "react";
import { clsx } from "clsx";

// =============================================================================
// Pill Types
// =============================================================================

export interface PillProps extends HTMLAttributes<HTMLSpanElement> {
  active?: boolean;
  disabled?: boolean;
  href?: string;
  onClick?: () => void;
  onRemove?: () => void;
  removable?: boolean;
  size?: "xs" | "sm" | "md" | "lg";
  variant?: "primary" | "secondary" | "success" | "warning" | "danger" | "neutral" | "info" | "violet" | "blue" | "amber" | "emerald";
}

// =============================================================================
// SharedPill Component
// =============================================================================

export function SharedPill({
  children,
  active = false,
  disabled = false,
  href,
  onClick,
  onRemove,
  removable = false,
  size = "sm",
  variant = "secondary",
  className,
  ...props
}: PillProps) {
  // Size classes
  const sizeClasses = {
    xs: "px-2 py-0.5 text-[10px]",
    sm: "px-2.5 py-1 text-[11px]",
    md: "px-3 py-1.5 text-[12px]",
    lg: "px-4 py-2 text-[13px]",
  };

  // Variant classes
  const variantClasses = {
    primary: {
      normal: "bg-[var(--accent-primary)]/10 text-[var(--accent-primary)] border-[var(--accent-primary)]/20",
      active: "bg-[var(--accent-primary)]/20 text-[var(--accent-primary)] border-[var(--accent-primary)]/30",
    },
    secondary: {
      normal: "bg-[var(--bg-elevated)] text-[var(--text-secondary)] border-[var(--border-subtle)]",
      active: "bg-[var(--bg-glass)] text-[var(--text-primary)] border-[var(--border-medium)]",
    },
    success: {
      normal: "bg-[var(--accent-emerald)]/10 text-[var(--accent-emerald)] border-[var(--accent-emerald)]/20",
      active: "bg-[var(--accent-emerald)]/20 text-[var(--accent-emerald)] border-[var(--accent-emerald)]/30",
    },
    warning: {
      normal: "bg-[var(--accent-amber)]/10 text-[var(--accent-amber)] border-[var(--accent-amber)]/20",
      active: "bg-[var(--accent-amber)]/20 text-[var(--accent-amber)] border-[var(--accent-amber)]/30",
    },
    danger: {
      normal: "bg-[var(--accent-red)]/10 text-[var(--accent-red)] border-[var(--accent-red)]/20",
      active: "bg-[var(--accent-red)]/20 text-[var(--accent-red)] border-[var(--accent-red)]/30",
    },
    neutral: {
      normal: "bg-[var(--bg-glass)] text-[var(--text-muted)] border-[var(--border-subtle)]",
      active: "bg-[var(--bg-elevated)] text-[var(--text-secondary)] border-[var(--border-medium)]",
    },
    // Additional variants
    info: {
      normal: "bg-blue-400/10 text-blue-400 border-blue-400/20",
      active: "bg-blue-400/20 text-blue-400 border-blue-400/30",
    },
    violet: {
      normal: "bg-violet-400/10 text-violet-400 border-violet-400/20",
      active: "bg-violet-400/20 text-violet-400 border-violet-400/30",
    },
    blue: {
      normal: "bg-blue-400/10 text-blue-400 border-blue-400/20",
      active: "bg-blue-400/20 text-blue-400 border-blue-400/30",
    },
    amber: {
      normal: "bg-amber-400/10 text-amber-400 border-amber-400/20",
      active: "bg-amber-400/20 text-amber-400 border-amber-400/30",
    },
    emerald: {
      normal: "bg-emerald-400/10 text-emerald-400 border-emerald-400/20",
      active: "bg-emerald-400/20 text-emerald-400 border-emerald-400/30",
    },
  };

  const v = variantClasses[variant];
  const stateClasses = active ? v.active : v.normal;
  const s = sizeClasses[size];

  // Build the pill content
  const pillContent = (
    <span
      className={clsx(
        "inline-flex items-center gap-1.5",
        "rounded-full",
        "border",
        "transition-colors",
        "duration-150",
        stateClasses,
        s,
        disabled && "opacity-50 cursor-not-allowed",
        className,
      )}
      {...props}
    >
      {children}
      {removable && !disabled && (
        <button
          type="button"
          onClick={(e) => {
            e.stopPropagation();
            onRemove?.();
          }}
          className="flex size-4 shrink-0 items-center justify-center rounded-full hover:bg-[var(--bg-elevated)] transition"
          aria-label="Remove"
        >
          <span className="text-[10px] font-bold" aria-hidden="true">
            ×
          </span>
        </button>
      )}
    </span>
  );

  // Decide how to render
  if (href && !disabled) {
    return (
      <Link href={href} className="inline-flex">
        {pillContent}
      </Link>
    );
  }

  if (onClick && !disabled) {
    return (
      <button
        type="button"
        onClick={onClick}
        className="inline-flex cursor-pointer"
        disabled={disabled}
      >
        {pillContent}
      </button>
    );
  }

  return pillContent;
}

// =============================================================================
// Convenience Pill Components
// =============================================================================

// Filter pill (for syllabus filters)
export function FilterPill({
  children,
  active,
  onClick,
  className,
  ...props
}: Omit<PillProps, "variant" | "removable">) {
  return (
    <SharedPill
      active={active}
      onClick={onClick}
      variant="secondary"
      size="sm"
      className={clsx("font-medium", className)}
      {...props}
    >
      {children}
    </SharedPill>
  );
}

// Topic pill (for chapter topics)
export function TopicPill({ children, className, ...props }: Omit<PillProps, "variant">) {
  return (
    <SharedPill
      variant="neutral"
      size="xs"
      className={clsx("font-medium text-[var(--text-ghost)]", className)}
      {...props}
    >
      {children}
    </SharedPill>
  );
}

// Priority pill (for exam priority)
export type PriorityLevel = "critical" | "high" | "moderate" | "optional";

const priorityConfig: Record<PriorityLevel, { variant: PillProps["variant"]; label: string }> = {
  critical: { variant: "danger", label: "Exam critical" },
  high: { variant: "warning", label: "High priority" },
  moderate: { variant: "success", label: "Moderate" },
  optional: { variant: "neutral", label: "Optional" },
};

export function PriorityPill({
  level,
  showLabel = false,
  className,
  ...props
}: { level: PriorityLevel; showLabel?: boolean } & Omit<PillProps, "variant" | "children">) {
  const config = priorityConfig[level];
  return (
    <SharedPill
      variant={config.variant}
      size="xs"
      className={className}
      {...props}
    >
      {showLabel ? config.label : level}
    </SharedPill>
  );
}

// Status pill
export type StatusType = "completed" | "in-progress" | "not-started" | "weak";

const statusConfig: Record<StatusType, { variant: PillProps["variant"]; label: string }> = {
  completed: { variant: "success", label: "Completed" },
  "in-progress": { variant: "warning", label: "In Progress" },
  "not-started": { variant: "neutral", label: "Not Started" },
  weak: { variant: "danger", label: "Weak" },
};

export function StatusPill({
  status,
  showLabel = false,
  className,
  ...props
}: { status: StatusType; showLabel?: boolean } & Omit<PillProps, "variant" | "children">) {
  const config = statusConfig[status];
  return (
    <SharedPill
      variant={config.variant}
      size="xs"
      className={className}
      {...props}
    >
      {showLabel ? config.label : status}
    </SharedPill>
  );
}

// Confidence pill (for teach page)
export type ConfidenceLevel = "high" | "medium" | "low" | "none";

const confidenceConfig: Record<ConfidenceLevel, { variant: PillProps["variant"]; label: string }> = {
  high: { variant: "success", label: "High confidence" },
  medium: { variant: "warning", label: "Likely match" },
  low: { variant: "danger", label: "Best guess" },
  none: { variant: "neutral", label: "No clear match" },
};

export function ConfidencePill({
  level,
  className,
  ...props
}: { level: ConfidenceLevel } & Omit<PillProps, "variant" | "children">) {
  const config = confidenceConfig[level];
  return (
    <SharedPill
      variant={config.variant}
      size="xs"
      className={clsx("font-semibold", className)}
      {...props}
    >
      {config.label}
    </SharedPill>
  );
}