@refraction-ui/astro 0.3.1 → 0.4.2
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/dist/astro-accordion/Button.astro +55 -0
- package/dist/astro-accordion/index.ts +1 -0
- package/dist/astro-ai/AIScript.astro +69 -0
- package/dist/astro-ai/TTSScript.astro +60 -0
- package/dist/astro-ai/index.ts +16 -0
- package/dist/astro-animated-text/AnimatedText.astro +81 -0
- package/dist/astro-animated-text/TypewriterText.astro +90 -0
- package/dist/astro-animated-text/index.ts +1 -0
- package/dist/astro-app-shell/AppShell.astro +195 -0
- package/dist/astro-app-shell/AppShellContent.astro +29 -0
- package/dist/astro-app-shell/AppShellHeader.astro +54 -0
- package/dist/astro-app-shell/AppShellMain.astro +18 -0
- package/dist/astro-app-shell/AppShellMobileNav.astro +27 -0
- package/dist/astro-app-shell/AppShellOverlay.astro +21 -0
- package/dist/astro-app-shell/AppShellSidebar.astro +26 -0
- package/dist/astro-app-shell/AuthShell.astro +31 -0
- package/dist/astro-app-shell/AuthShellCard.astro +24 -0
- package/dist/astro-app-shell/PageShell.astro +36 -0
- package/dist/astro-app-shell/PageShellFooter.astro +30 -0
- package/dist/astro-app-shell/PageShellNav.astro +33 -0
- package/dist/astro-app-shell/PageShellSection.astro +32 -0
- package/dist/astro-app-shell/index.ts +21 -0
- package/dist/astro-auth/AuthGuard.astro +133 -0
- package/dist/astro-auth/index.ts +5 -0
- package/dist/astro-avatar/Avatar.astro +22 -0
- package/dist/astro-avatar/AvatarFallback.astro +18 -0
- package/dist/astro-avatar/AvatarImage.astro +48 -0
- package/dist/astro-avatar/index.ts +1 -0
- package/dist/astro-avatar-group/AvatarGroup.astro +42 -0
- package/dist/astro-avatar-group/index.ts +1 -0
- package/dist/astro-badge/Badge.astro +27 -0
- package/dist/astro-badge/index.ts +1 -0
- package/dist/astro-bottom-nav/BottomNav.astro +40 -0
- package/dist/astro-bottom-nav/index.ts +1 -0
- package/dist/astro-breadcrumbs/Breadcrumbs.astro +56 -0
- package/dist/astro-breadcrumbs/index.ts +1 -0
- package/dist/astro-button/Button.astro +55 -0
- package/dist/astro-button/index.ts +1 -0
- package/dist/astro-calendar/Calendar.astro +259 -0
- package/dist/astro-calendar/index.ts +1 -0
- package/dist/astro-callout/Callout.astro +3 -0
- package/dist/astro-callout/index.ts +1 -0
- package/dist/astro-card/Card.astro +20 -0
- package/dist/astro-card/CardContent.astro +13 -0
- package/dist/astro-card/CardDescription.astro +13 -0
- package/dist/astro-card/CardFooter.astro +13 -0
- package/dist/astro-card/CardHeader.astro +13 -0
- package/dist/astro-card/CardTitle.astro +15 -0
- package/dist/astro-card/index.ts +1 -0
- package/dist/astro-card-grid/CardGrid.astro +17 -0
- package/dist/astro-card-grid/index.ts +1 -0
- package/dist/astro-carousel/Button.astro +55 -0
- package/dist/astro-carousel/index.ts +1 -0
- package/dist/astro-charts/Bars.astro +53 -0
- package/dist/astro-charts/Chart.astro +31 -0
- package/dist/astro-charts/Circles.astro +48 -0
- package/dist/astro-charts/Gradient.astro +34 -0
- package/dist/astro-charts/Histogram.astro +107 -0
- package/dist/astro-charts/Line.astro +55 -0
- package/dist/astro-charts/PieChart.astro +63 -0
- package/dist/astro-charts/ScatterPlot.astro +95 -0
- package/dist/astro-charts/XAxis.astro +46 -0
- package/dist/astro-charts/YAxis.astro +44 -0
- package/dist/astro-charts/index.ts +26 -0
- package/dist/astro-checkbox/Checkbox.astro +129 -0
- package/dist/astro-checkbox/index.ts +1 -0
- package/dist/astro-code-block/CodeBlock.astro +3 -0
- package/dist/astro-code-block/index.ts +1 -0
- package/dist/astro-code-editor/CodeEditor.astro +123 -0
- package/dist/astro-code-editor/index.ts +1 -0
- package/dist/astro-collapsible/Collapsible.astro +58 -0
- package/dist/astro-collapsible/CollapsibleContent.astro +21 -0
- package/dist/astro-collapsible/CollapsibleTrigger.astro +17 -0
- package/dist/astro-collapsible/index.ts +1 -0
- package/dist/astro-command/Command.astro +170 -0
- package/dist/astro-command/CommandEmpty.astro +17 -0
- package/dist/astro-command/CommandGroup.astro +25 -0
- package/dist/astro-command/CommandInput.astro +21 -0
- package/dist/astro-command/CommandItem.astro +26 -0
- package/dist/astro-command/CommandList.astro +17 -0
- package/dist/astro-command/CommandSeparator.astro +14 -0
- package/dist/astro-command/index.ts +1 -0
- package/dist/astro-command-input/CommandInput.astro +6 -0
- package/dist/astro-command-input/index.ts +1 -0
- package/dist/astro-content-protection/ContentProtection.astro +104 -0
- package/dist/astro-content-protection/index.ts +1 -0
- package/dist/astro-data-table/DataTable.astro +263 -0
- package/dist/astro-data-table/index.ts +1 -0
- package/dist/astro-date-picker/DatePicker.astro +398 -0
- package/dist/astro-date-picker/index.ts +1 -0
- package/dist/astro-device-frame/DeviceFrame.astro +44 -0
- package/dist/astro-device-frame/index.ts +1 -0
- package/dist/astro-dialog/Dialog.astro +138 -0
- package/dist/astro-dialog/DialogClose.astro +16 -0
- package/dist/astro-dialog/DialogContent.astro +24 -0
- package/dist/astro-dialog/DialogDescription.astro +15 -0
- package/dist/astro-dialog/DialogFooter.astro +14 -0
- package/dist/astro-dialog/DialogHeader.astro +14 -0
- package/dist/astro-dialog/DialogOverlay.astro +17 -0
- package/dist/astro-dialog/DialogTitle.astro +15 -0
- package/dist/astro-dialog/DialogTrigger.astro +18 -0
- package/dist/astro-dialog/index.ts +1 -0
- package/dist/astro-diff-viewer/DiffViewer.astro +371 -0
- package/dist/astro-diff-viewer/index.ts +1 -0
- package/dist/astro-dropdown-menu/DropdownMenu.astro +138 -0
- package/dist/astro-dropdown-menu/DropdownMenuContent.astro +20 -0
- package/dist/astro-dropdown-menu/DropdownMenuItem.astro +21 -0
- package/dist/astro-dropdown-menu/DropdownMenuLabel.astro +14 -0
- package/dist/astro-dropdown-menu/DropdownMenuSeparator.astro +14 -0
- package/dist/astro-dropdown-menu/DropdownMenuTrigger.astro +18 -0
- package/dist/astro-dropdown-menu/index.ts +1 -0
- package/dist/astro-emoji-picker/EmojiPicker.astro +255 -0
- package/dist/astro-emoji-picker/index.ts +1 -0
- package/dist/astro-feedback-dialog/FeedbackDialog.astro +152 -0
- package/dist/astro-feedback-dialog/index.ts +1 -0
- package/dist/astro-file-tree/astro-file-tree.astro +4 -0
- package/dist/astro-file-tree/index.ts +1 -0
- package/dist/astro-file-upload/FileUpload.astro +306 -0
- package/dist/astro-file-upload/index.ts +1 -0
- package/dist/astro-footer/Footer.astro +61 -0
- package/dist/astro-footer/index.ts +1 -0
- package/dist/astro-icon-system/astro-icon-system.astro +4 -0
- package/dist/astro-icon-system/index.ts +1 -0
- package/dist/astro-inline-editor/InlineEditor.astro +169 -0
- package/dist/astro-inline-editor/index.ts +1 -0
- package/dist/astro-input/Input.astro +49 -0
- package/dist/astro-input/index.ts +1 -0
- package/dist/astro-input-group/InputGroup.astro +29 -0
- package/dist/astro-input-group/InputGroupAddon.astro +14 -0
- package/dist/astro-input-group/InputGroupButton.astro +19 -0
- package/dist/astro-input-group/InputGroupText.astro +11 -0
- package/dist/astro-input-group/index.ts +1 -0
- package/dist/astro-install-prompt/InstallPrompt.astro +115 -0
- package/dist/astro-install-prompt/index.ts +1 -0
- package/dist/astro-keyboard-shortcut/KeyboardShortcut.astro +83 -0
- package/dist/astro-keyboard-shortcut/ShortcutBadge.astro +41 -0
- package/dist/astro-keyboard-shortcut/index.ts +1 -0
- package/dist/astro-language-selector/LanguageSelector.astro +247 -0
- package/dist/astro-language-selector/index.ts +1 -0
- package/dist/astro-link-card/LinkCard.astro +17 -0
- package/dist/astro-link-card/index.ts +1 -0
- package/dist/astro-markdown-renderer/MarkdownRenderer.astro +62 -0
- package/dist/astro-markdown-renderer/index.ts +1 -0
- package/dist/astro-mobile-nav/MobileNav.astro +84 -0
- package/dist/astro-mobile-nav/MobileNavContent.astro +29 -0
- package/dist/astro-mobile-nav/MobileNavLink.astro +16 -0
- package/dist/astro-mobile-nav/MobileNavTrigger.astro +57 -0
- package/dist/astro-mobile-nav/index.ts +1 -0
- package/dist/astro-navbar/Navbar.astro +49 -0
- package/dist/astro-navbar/index.ts +1 -0
- package/dist/astro-otp-input/OtpInput.astro +253 -0
- package/dist/astro-otp-input/index.ts +1 -0
- package/dist/astro-pagination/Pagination.astro +3 -0
- package/dist/astro-pagination/index.ts +1 -0
- package/dist/astro-payment/Payment.astro +19 -0
- package/dist/astro-payment/index.ts +1 -0
- package/dist/astro-popover/Popover.astro +87 -0
- package/dist/astro-popover/PopoverClose.astro +16 -0
- package/dist/astro-popover/PopoverContent.astro +23 -0
- package/dist/astro-popover/PopoverTrigger.astro +18 -0
- package/dist/astro-popover/index.ts +1 -0
- package/dist/astro-presence-indicator/PresenceIndicator.astro +26 -0
- package/dist/astro-presence-indicator/index.ts +1 -0
- package/dist/astro-progress-display/BadgeDisplay.astro +33 -0
- package/dist/astro-progress-display/ProgressBar.astro +27 -0
- package/dist/astro-progress-display/StatsGrid.astro +32 -0
- package/dist/astro-progress-display/index.ts +1 -0
- package/dist/astro-radio/RadioGroup.astro +111 -0
- package/dist/astro-radio/RadioItem.astro +36 -0
- package/dist/astro-radio/index.ts +1 -0
- package/dist/astro-reaction-bar/ReactionBar.astro +117 -0
- package/dist/astro-reaction-bar/index.ts +1 -0
- package/dist/astro-resizable-layout/ResizableDivider.astro +27 -0
- package/dist/astro-resizable-layout/ResizableLayout.astro +162 -0
- package/dist/astro-resizable-layout/ResizablePane.astro +28 -0
- package/dist/astro-resizable-layout/index.ts +11 -0
- package/dist/astro-rich-editor/RichEditor.astro +260 -0
- package/dist/astro-rich-editor/index.ts +25 -0
- package/dist/astro-search-bar/SearchBar.astro +140 -0
- package/dist/astro-search-bar/SearchResultItem.astro +16 -0
- package/dist/astro-search-bar/SearchResults.astro +17 -0
- package/dist/astro-search-bar/index.ts +1 -0
- package/dist/astro-select/Select.astro +165 -0
- package/dist/astro-select/SelectContent.astro +19 -0
- package/dist/astro-select/SelectItem.astro +42 -0
- package/dist/astro-select/SelectTrigger.astro +36 -0
- package/dist/astro-select/index.ts +1 -0
- package/dist/astro-sidebar/Sidebar.astro +64 -0
- package/dist/astro-sidebar/index.ts +1 -0
- package/dist/astro-skeleton/Skeleton.astro +39 -0
- package/dist/astro-skeleton/SkeletonText.astro +22 -0
- package/dist/astro-skeleton/index.ts +1 -0
- package/dist/astro-skip-to-content/SkipToContent.astro +3 -0
- package/dist/astro-skip-to-content/index.ts +1 -0
- package/dist/astro-slide-viewer/SlideViewer.astro +231 -0
- package/dist/astro-slide-viewer/index.ts +1 -0
- package/dist/astro-slider/index.ts +1 -0
- package/dist/astro-status-indicator/StatusIndicator.astro +31 -0
- package/dist/astro-status-indicator/index.ts +1 -0
- package/dist/astro-steps/Steps.astro +3 -0
- package/dist/astro-steps/index.ts +1 -0
- package/dist/astro-switch/Switch.astro +89 -0
- package/dist/astro-switch/index.ts +1 -0
- package/dist/astro-table-of-contents/TableOfContents.astro +53 -0
- package/dist/astro-table-of-contents/index.ts +1 -0
- package/dist/astro-tabs/Tabs.astro +96 -0
- package/dist/astro-tabs/TabsContent.astro +20 -0
- package/dist/astro-tabs/TabsList.astro +16 -0
- package/dist/astro-tabs/TabsTrigger.astro +24 -0
- package/dist/astro-tabs/index.ts +1 -0
- package/dist/astro-textarea/Textarea.astro +51 -0
- package/dist/astro-textarea/index.ts +1 -0
- package/dist/astro-theme/ThemeScript.astro +13 -0
- package/dist/astro-theme/ThemeToggle.astro +279 -0
- package/dist/astro-theme/index.ts +1 -0
- package/dist/astro-thread-view/ThreadView.astro +159 -0
- package/dist/astro-thread-view/index.ts +1 -0
- package/dist/astro-toast/Toast.astro +49 -0
- package/dist/astro-toast/Toaster.astro +142 -0
- package/dist/astro-toast/index.ts +1 -0
- package/dist/astro-tooltip/Tooltip.astro +95 -0
- package/dist/astro-tooltip/TooltipContent.astro +22 -0
- package/dist/astro-tooltip/TooltipTrigger.astro +16 -0
- package/dist/astro-tooltip/index.ts +1 -0
- package/dist/astro-version-selector/VersionSelector.astro +174 -0
- package/dist/astro-version-selector/index.ts +1 -0
- package/dist/astro-video-player/VideoPlayer.astro +153 -0
- package/dist/astro-video-player/index.ts +1 -0
- package/dist/index.ts +77 -0
- package/dist/shared/a11y.ts +33 -0
- package/dist/shared/aria.ts +30 -0
- package/dist/shared/cn.ts +35 -0
- package/dist/shared/cva.ts +79 -0
- package/dist/shared/engine-adapter.ts +10 -0
- package/dist/shared/focus-trap.ts +123 -0
- package/dist/shared/index.ts +60 -0
- package/dist/shared/keyboard.ts +36 -0
- package/dist/shared/live-region.ts +90 -0
- package/dist/shared/motion.ts +15 -0
- package/dist/shared/skip-link.ts +35 -0
- package/dist/shared/state-machine.ts +57 -0
- package/dist/shared/tokens.ts +16 -0
- package/dist/shared/types.ts +45 -0
- package/dist/shared/variants.ts +17 -0
- package/package.json +22 -20
- package/src/index.ts +0 -92
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Circles — circle markers for scatter/bubble chart overlays.
|
|
4
|
+
* Accepts pre-computed x/y value arrays.
|
|
5
|
+
*/
|
|
6
|
+
import { createLinearScale, computeExtent } from '@refraction-ui/charts'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** X values for each data point */
|
|
10
|
+
xValues: number[]
|
|
11
|
+
/** Y values for each data point */
|
|
12
|
+
yValues: number[]
|
|
13
|
+
/** Bounded width of the chart area */
|
|
14
|
+
boundedWidth: number
|
|
15
|
+
/** Bounded height of the chart area */
|
|
16
|
+
boundedHeight: number
|
|
17
|
+
/** Circle radius (default 4) */
|
|
18
|
+
r?: number
|
|
19
|
+
/** Fill color (default 'currentColor') */
|
|
20
|
+
fill?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
xValues,
|
|
25
|
+
yValues,
|
|
26
|
+
boundedWidth,
|
|
27
|
+
boundedHeight,
|
|
28
|
+
r = 4,
|
|
29
|
+
fill = 'currentColor',
|
|
30
|
+
} = Astro.props
|
|
31
|
+
|
|
32
|
+
const [xMin, xMax] = computeExtent(xValues)
|
|
33
|
+
const [yMin, yMax] = computeExtent(yValues)
|
|
34
|
+
|
|
35
|
+
const xScale = createLinearScale([xMin, xMax], [0, boundedWidth])
|
|
36
|
+
const yScale = createLinearScale([yMin, yMax], [boundedHeight, 0])
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
<g data-rfr-chart-circles>
|
|
40
|
+
{xValues.map((xv, i) => (
|
|
41
|
+
<circle
|
|
42
|
+
cx={xScale(xv)}
|
|
43
|
+
cy={yScale(yValues[i])}
|
|
44
|
+
r={r}
|
|
45
|
+
fill={fill}
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</g>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Gradient — SVG linear gradient definition.
|
|
4
|
+
* Use inside a Chart or any SVG element; reference via `url(#id)` in fill/stroke.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
/** Gradient ID for referencing */
|
|
9
|
+
id: string
|
|
10
|
+
/** Start color */
|
|
11
|
+
from: string
|
|
12
|
+
/** End color */
|
|
13
|
+
to: string
|
|
14
|
+
/** Direction (default 'vertical') */
|
|
15
|
+
direction?: 'vertical' | 'horizontal'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { id, from, to, direction = 'vertical' } = Astro.props
|
|
19
|
+
|
|
20
|
+
const isVertical = direction === 'vertical'
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<defs>
|
|
24
|
+
<linearGradient
|
|
25
|
+
id={id}
|
|
26
|
+
x1="0"
|
|
27
|
+
y1="0"
|
|
28
|
+
x2={isVertical ? '0' : '1'}
|
|
29
|
+
y2={isVertical ? '1' : '0'}
|
|
30
|
+
>
|
|
31
|
+
<stop offset="0%" stop-color={from} />
|
|
32
|
+
<stop offset="100%" stop-color={to} />
|
|
33
|
+
</linearGradient>
|
|
34
|
+
</defs>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Histogram — standalone histogram chart.
|
|
4
|
+
* Accepts raw numeric data and renders binned bars with axes.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
computeHistogramBins,
|
|
8
|
+
createLinearScale,
|
|
9
|
+
createBandScale,
|
|
10
|
+
combineDimensions,
|
|
11
|
+
formatTick,
|
|
12
|
+
type Margin,
|
|
13
|
+
} from '@refraction-ui/charts'
|
|
14
|
+
|
|
15
|
+
interface Props extends astroHTML.JSX.HTMLAttributes {
|
|
16
|
+
/** Raw numeric data */
|
|
17
|
+
data: number[]
|
|
18
|
+
/** Width of the SVG (default 600) */
|
|
19
|
+
width?: number
|
|
20
|
+
/** Height of the SVG (default 400) */
|
|
21
|
+
height?: number
|
|
22
|
+
/** Number of bins (default 10) */
|
|
23
|
+
bins?: number
|
|
24
|
+
/** Fill color (default 'steelblue') */
|
|
25
|
+
fill?: string
|
|
26
|
+
/** Custom margin */
|
|
27
|
+
margin?: Partial<Margin>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
data,
|
|
32
|
+
width = 600,
|
|
33
|
+
height = 400,
|
|
34
|
+
bins: binCount = 10,
|
|
35
|
+
fill = 'steelblue',
|
|
36
|
+
margin,
|
|
37
|
+
class: className,
|
|
38
|
+
...props
|
|
39
|
+
} = Astro.props
|
|
40
|
+
|
|
41
|
+
const dimensions = combineDimensions({ width, height, margin })
|
|
42
|
+
const { boundedWidth, boundedHeight } = dimensions
|
|
43
|
+
|
|
44
|
+
const histBins = computeHistogramBins(data, binCount)
|
|
45
|
+
const maxCount = Math.max(...histBins.map((b) => b.count))
|
|
46
|
+
|
|
47
|
+
const labels = histBins.map((b) => `${formatTick(b.x0, 'number')}-${formatTick(b.x1, 'number')}`)
|
|
48
|
+
const xScale = createBandScale(labels, [0, boundedWidth], 0.05)
|
|
49
|
+
const yScale = createLinearScale([0, maxCount], [boundedHeight, 0])
|
|
50
|
+
|
|
51
|
+
const yTicks = yScale.ticks(5)
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
<svg
|
|
55
|
+
width={width}
|
|
56
|
+
height={height}
|
|
57
|
+
class={className}
|
|
58
|
+
data-rfr-chart-histogram
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
<g transform={`translate(${dimensions.margin.left},${dimensions.margin.top})`}>
|
|
62
|
+
{histBins.map((bin, i) => {
|
|
63
|
+
const label = labels[i]
|
|
64
|
+
const barX = xScale(label)
|
|
65
|
+
const barY = yScale(bin.count)
|
|
66
|
+
const barHeight = boundedHeight - barY
|
|
67
|
+
const barWidth = xScale.bandwidth()
|
|
68
|
+
return (
|
|
69
|
+
<rect
|
|
70
|
+
x={barX}
|
|
71
|
+
y={barY}
|
|
72
|
+
width={barWidth}
|
|
73
|
+
height={barHeight}
|
|
74
|
+
fill={fill}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
})}
|
|
78
|
+
{/* X Axis */}
|
|
79
|
+
<g transform={`translate(0,${boundedHeight})`}>
|
|
80
|
+
{labels.map((label, i) => {
|
|
81
|
+
const x = xScale(label) + xScale.bandwidth() / 2
|
|
82
|
+
return (
|
|
83
|
+
<g transform={`translate(${x},0)`}>
|
|
84
|
+
<line y2={6} stroke="currentColor" />
|
|
85
|
+
<text y={18} text-anchor="middle" font-size={10} fill="currentColor">
|
|
86
|
+
{label}
|
|
87
|
+
</text>
|
|
88
|
+
</g>
|
|
89
|
+
)
|
|
90
|
+
})}
|
|
91
|
+
</g>
|
|
92
|
+
{/* Y Axis */}
|
|
93
|
+
<g>
|
|
94
|
+
{yTicks.map((tick) => {
|
|
95
|
+
const y = yScale(tick)
|
|
96
|
+
return (
|
|
97
|
+
<g transform={`translate(0,${y})`}>
|
|
98
|
+
<line x2={-6} stroke="currentColor" />
|
|
99
|
+
<text x={-9} dy="0.32em" text-anchor="end" font-size={10} fill="currentColor">
|
|
100
|
+
{formatTick(tick, 'number')}
|
|
101
|
+
</text>
|
|
102
|
+
</g>
|
|
103
|
+
)
|
|
104
|
+
})}
|
|
105
|
+
</g>
|
|
106
|
+
</g>
|
|
107
|
+
</svg>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Line — line/area chart path, server-rendered as an SVG <path>.
|
|
4
|
+
* Accepts pre-computed x/y value arrays.
|
|
5
|
+
*/
|
|
6
|
+
import { createLinearScale, computeExtent, linePath } from '@refraction-ui/charts'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** X values for each data point */
|
|
10
|
+
xValues: number[]
|
|
11
|
+
/** Y values for each data point */
|
|
12
|
+
yValues: number[]
|
|
13
|
+
/** Bounded width of the chart area */
|
|
14
|
+
boundedWidth: number
|
|
15
|
+
/** Bounded height of the chart area */
|
|
16
|
+
boundedHeight: number
|
|
17
|
+
/** Stroke color (default 'currentColor') */
|
|
18
|
+
stroke?: string
|
|
19
|
+
/** Stroke width (default 2) */
|
|
20
|
+
strokeWidth?: number
|
|
21
|
+
/** Fill (default 'none') */
|
|
22
|
+
fill?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
xValues,
|
|
27
|
+
yValues,
|
|
28
|
+
boundedWidth,
|
|
29
|
+
boundedHeight,
|
|
30
|
+
stroke = 'currentColor',
|
|
31
|
+
strokeWidth = 2,
|
|
32
|
+
fill = 'none',
|
|
33
|
+
} = Astro.props
|
|
34
|
+
|
|
35
|
+
const [xMin, xMax] = computeExtent(xValues)
|
|
36
|
+
const [yMin, yMax] = computeExtent(yValues)
|
|
37
|
+
|
|
38
|
+
const xScale = createLinearScale([xMin, xMax], [0, boundedWidth])
|
|
39
|
+
const yScale = createLinearScale([yMin, yMax], [boundedHeight, 0])
|
|
40
|
+
|
|
41
|
+
const points = xValues.map((xv, i) => ({
|
|
42
|
+
x: xScale(xv),
|
|
43
|
+
y: yScale(yValues[i]),
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
const d = linePath(points)
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
<path
|
|
50
|
+
d={d}
|
|
51
|
+
stroke={stroke}
|
|
52
|
+
stroke-width={strokeWidth}
|
|
53
|
+
fill={fill}
|
|
54
|
+
data-rfr-chart-line
|
|
55
|
+
/>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* PieChart — standalone pie/donut chart rendered as SVG arcs.
|
|
4
|
+
*/
|
|
5
|
+
import { arcPath } from '@refraction-ui/charts'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_COLORS = [
|
|
8
|
+
'#4e79a7', '#f28e2b', '#e15759', '#76b7b2',
|
|
9
|
+
'#59a14f', '#edc948', '#b07aa1', '#ff9da7',
|
|
10
|
+
'#9c755f', '#bab0ac',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
interface Props extends astroHTML.JSX.HTMLAttributes {
|
|
14
|
+
/** Numeric values for each slice */
|
|
15
|
+
values: number[]
|
|
16
|
+
/** Width of the SVG (default 300) */
|
|
17
|
+
width?: number
|
|
18
|
+
/** Height of the SVG (default 300) */
|
|
19
|
+
height?: number
|
|
20
|
+
/** Slice colors */
|
|
21
|
+
colors?: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
values,
|
|
26
|
+
width = 300,
|
|
27
|
+
height = 300,
|
|
28
|
+
colors = DEFAULT_COLORS,
|
|
29
|
+
class: className,
|
|
30
|
+
...props
|
|
31
|
+
} = Astro.props
|
|
32
|
+
|
|
33
|
+
const cx = width / 2
|
|
34
|
+
const cy = height / 2
|
|
35
|
+
const radius = Math.min(cx, cy) - 10
|
|
36
|
+
|
|
37
|
+
const total = values.reduce((sum, v) => sum + v, 0)
|
|
38
|
+
|
|
39
|
+
let currentAngle = -Math.PI / 2
|
|
40
|
+
|
|
41
|
+
const arcs = values.map((val, i) => {
|
|
42
|
+
const sliceAngle = (val / total) * Math.PI * 2
|
|
43
|
+
const startAngle = currentAngle
|
|
44
|
+
const endAngle = currentAngle + sliceAngle
|
|
45
|
+
currentAngle = endAngle
|
|
46
|
+
return { startAngle, endAngle, color: colors[i % colors.length] }
|
|
47
|
+
})
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<svg
|
|
51
|
+
width={width}
|
|
52
|
+
height={height}
|
|
53
|
+
class={className}
|
|
54
|
+
data-rfr-chart-pie
|
|
55
|
+
{...props}
|
|
56
|
+
>
|
|
57
|
+
{arcs.map((arc) => (
|
|
58
|
+
<path
|
|
59
|
+
d={arcPath(cx, cy, radius, arc.startAngle, arc.endAngle)}
|
|
60
|
+
fill={arc.color}
|
|
61
|
+
/>
|
|
62
|
+
))}
|
|
63
|
+
</svg>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* ScatterPlot — standalone scatter plot chart.
|
|
4
|
+
* Accepts pre-computed x/y arrays and renders circles with axes.
|
|
5
|
+
*/
|
|
6
|
+
import { createLinearScale, computeExtent, combineDimensions, formatTick, type Margin } from '@refraction-ui/charts'
|
|
7
|
+
|
|
8
|
+
interface Props extends astroHTML.JSX.HTMLAttributes {
|
|
9
|
+
/** X values for each data point */
|
|
10
|
+
xValues: number[]
|
|
11
|
+
/** Y values for each data point */
|
|
12
|
+
yValues: number[]
|
|
13
|
+
/** Width of the SVG (default 600) */
|
|
14
|
+
width?: number
|
|
15
|
+
/** Height of the SVG (default 400) */
|
|
16
|
+
height?: number
|
|
17
|
+
/** Circle radius (default 4) */
|
|
18
|
+
r?: number
|
|
19
|
+
/** Fill color (default 'steelblue') */
|
|
20
|
+
fill?: string
|
|
21
|
+
/** Custom margin */
|
|
22
|
+
margin?: Partial<Margin>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
xValues,
|
|
27
|
+
yValues,
|
|
28
|
+
width = 600,
|
|
29
|
+
height = 400,
|
|
30
|
+
r = 4,
|
|
31
|
+
fill = 'steelblue',
|
|
32
|
+
margin,
|
|
33
|
+
class: className,
|
|
34
|
+
...props
|
|
35
|
+
} = Astro.props
|
|
36
|
+
|
|
37
|
+
const dimensions = combineDimensions({ width, height, margin })
|
|
38
|
+
const { boundedWidth, boundedHeight } = dimensions
|
|
39
|
+
|
|
40
|
+
const [xMin, xMax] = computeExtent(xValues)
|
|
41
|
+
const [yMin, yMax] = computeExtent(yValues)
|
|
42
|
+
|
|
43
|
+
const xScale = createLinearScale([xMin, xMax], [0, boundedWidth])
|
|
44
|
+
const yScale = createLinearScale([yMin, yMax], [boundedHeight, 0])
|
|
45
|
+
|
|
46
|
+
const xTicks = xScale.ticks(5)
|
|
47
|
+
const yTicks = yScale.ticks(5)
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<svg
|
|
51
|
+
width={width}
|
|
52
|
+
height={height}
|
|
53
|
+
class={className}
|
|
54
|
+
data-rfr-chart-scatter
|
|
55
|
+
{...props}
|
|
56
|
+
>
|
|
57
|
+
<g transform={`translate(${dimensions.margin.left},${dimensions.margin.top})`}>
|
|
58
|
+
{xValues.map((xv, i) => (
|
|
59
|
+
<circle
|
|
60
|
+
cx={xScale(xv)}
|
|
61
|
+
cy={yScale(yValues[i])}
|
|
62
|
+
r={r}
|
|
63
|
+
fill={fill}
|
|
64
|
+
/>
|
|
65
|
+
))}
|
|
66
|
+
{/* X Axis */}
|
|
67
|
+
<g transform={`translate(0,${boundedHeight})`}>
|
|
68
|
+
{xTicks.map((tick) => {
|
|
69
|
+
const px = xScale(tick)
|
|
70
|
+
return (
|
|
71
|
+
<g transform={`translate(${px},0)`}>
|
|
72
|
+
<line y2={6} stroke="currentColor" />
|
|
73
|
+
<text y={18} text-anchor="middle" font-size={10} fill="currentColor">
|
|
74
|
+
{formatTick(tick, 'number')}
|
|
75
|
+
</text>
|
|
76
|
+
</g>
|
|
77
|
+
)
|
|
78
|
+
})}
|
|
79
|
+
</g>
|
|
80
|
+
{/* Y Axis */}
|
|
81
|
+
<g>
|
|
82
|
+
{yTicks.map((tick) => {
|
|
83
|
+
const py = yScale(tick)
|
|
84
|
+
return (
|
|
85
|
+
<g transform={`translate(0,${py})`}>
|
|
86
|
+
<line x2={-6} stroke="currentColor" />
|
|
87
|
+
<text x={-9} dy="0.32em" text-anchor="end" font-size={10} fill="currentColor">
|
|
88
|
+
{formatTick(tick, 'number')}
|
|
89
|
+
</text>
|
|
90
|
+
</g>
|
|
91
|
+
)
|
|
92
|
+
})}
|
|
93
|
+
</g>
|
|
94
|
+
</g>
|
|
95
|
+
</svg>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* XAxis — horizontal axis with tick marks and labels.
|
|
4
|
+
* Designed to be used inside a Chart's <g> element.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
/** Tick values (strings or numbers) */
|
|
9
|
+
ticks: (number | string)[]
|
|
10
|
+
/** Pixel positions for each tick value */
|
|
11
|
+
positions: number[]
|
|
12
|
+
/** Distance from top of bounded area to axis line */
|
|
13
|
+
height: number
|
|
14
|
+
/** Tick mark length (default 6) */
|
|
15
|
+
tickSize?: number
|
|
16
|
+
/** Font size for labels (default 12) */
|
|
17
|
+
fontSize?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
ticks,
|
|
22
|
+
positions,
|
|
23
|
+
height,
|
|
24
|
+
tickSize = 6,
|
|
25
|
+
fontSize = 12,
|
|
26
|
+
} = Astro.props
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<g transform={`translate(0,${height})`} data-rfr-chart-xaxis>
|
|
30
|
+
{ticks.map((tick, i) => {
|
|
31
|
+
const x = positions[i]
|
|
32
|
+
return (
|
|
33
|
+
<g transform={`translate(${x},0)`}>
|
|
34
|
+
<line y2={tickSize} stroke="currentColor" />
|
|
35
|
+
<text
|
|
36
|
+
y={tickSize + 9}
|
|
37
|
+
text-anchor="middle"
|
|
38
|
+
font-size={fontSize}
|
|
39
|
+
fill="currentColor"
|
|
40
|
+
>
|
|
41
|
+
{String(tick)}
|
|
42
|
+
</text>
|
|
43
|
+
</g>
|
|
44
|
+
)
|
|
45
|
+
})}
|
|
46
|
+
</g>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* YAxis — vertical axis with tick marks and labels.
|
|
4
|
+
* Designed to be used inside a Chart's <g> element.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
/** Tick values (strings or numbers) */
|
|
9
|
+
ticks: (number | string)[]
|
|
10
|
+
/** Pixel positions for each tick value */
|
|
11
|
+
positions: number[]
|
|
12
|
+
/** Tick mark length (default 6) */
|
|
13
|
+
tickSize?: number
|
|
14
|
+
/** Font size for labels (default 12) */
|
|
15
|
+
fontSize?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
ticks,
|
|
20
|
+
positions,
|
|
21
|
+
tickSize = 6,
|
|
22
|
+
fontSize = 12,
|
|
23
|
+
} = Astro.props
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<g data-rfr-chart-yaxis>
|
|
27
|
+
{ticks.map((tick, i) => {
|
|
28
|
+
const y = positions[i]
|
|
29
|
+
return (
|
|
30
|
+
<g transform={`translate(0,${y})`}>
|
|
31
|
+
<line x2={-tickSize} stroke="currentColor" />
|
|
32
|
+
<text
|
|
33
|
+
x={-tickSize - 4}
|
|
34
|
+
dy="0.32em"
|
|
35
|
+
text-anchor="end"
|
|
36
|
+
font-size={fontSize}
|
|
37
|
+
fill="currentColor"
|
|
38
|
+
>
|
|
39
|
+
{String(tick)}
|
|
40
|
+
</text>
|
|
41
|
+
</g>
|
|
42
|
+
)
|
|
43
|
+
})}
|
|
44
|
+
</g>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { default as Chart } from './Chart.astro'
|
|
2
|
+
export { default as Bars } from './Bars.astro'
|
|
3
|
+
export { default as Line } from './Line.astro'
|
|
4
|
+
export { default as PieChart } from './PieChart.astro'
|
|
5
|
+
export { default as ScatterPlot } from './ScatterPlot.astro'
|
|
6
|
+
export { default as Histogram } from './Histogram.astro'
|
|
7
|
+
export { default as XAxis } from './XAxis.astro'
|
|
8
|
+
export { default as YAxis } from './YAxis.astro'
|
|
9
|
+
export { default as Gradient } from './Gradient.astro'
|
|
10
|
+
export { default as Circles } from './Circles.astro'
|
|
11
|
+
|
|
12
|
+
// Re-export core types and utilities
|
|
13
|
+
export {
|
|
14
|
+
combineDimensions,
|
|
15
|
+
createLinearScale,
|
|
16
|
+
createBandScale,
|
|
17
|
+
computeExtent,
|
|
18
|
+
computeHistogramBins,
|
|
19
|
+
linePath,
|
|
20
|
+
areaPath,
|
|
21
|
+
arcPath,
|
|
22
|
+
formatTick,
|
|
23
|
+
generateTicks,
|
|
24
|
+
COLORBLIND_SAFE_PALETTE,
|
|
25
|
+
getChartColor,
|
|
26
|
+
} from '@refraction-ui/charts'
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
import {
|
|
3
|
+
createCheckbox,
|
|
4
|
+
checkboxVariants,
|
|
5
|
+
checkIconPath,
|
|
6
|
+
indeterminateIconPath,
|
|
7
|
+
type CheckedState,
|
|
8
|
+
} from '@refraction-ui/checkbox'
|
|
9
|
+
import { cn } from '../shared/index.ts'
|
|
10
|
+
|
|
11
|
+
interface Props extends astroHTML.JSX.HTMLAttributes {
|
|
12
|
+
checked?: CheckedState
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
size?: 'sm' | 'default' | 'lg'
|
|
15
|
+
name?: string
|
|
16
|
+
value?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { checked = false, disabled = false, size = 'default', name, value, class: className, ...props } = Astro.props
|
|
20
|
+
const api = createCheckbox({ checked, disabled })
|
|
21
|
+
const checkedVariant = checked === 'indeterminate' ? 'indeterminate' : checked ? 'true' : 'false'
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
<button
|
|
25
|
+
type="button"
|
|
26
|
+
class={cn(checkboxVariants({ checked: checkedVariant, size }), className)}
|
|
27
|
+
disabled={disabled}
|
|
28
|
+
data-rfr-checkbox
|
|
29
|
+
{...api.ariaProps}
|
|
30
|
+
{...api.dataAttributes}
|
|
31
|
+
{...props}
|
|
32
|
+
>
|
|
33
|
+
{checked === true && (
|
|
34
|
+
<svg
|
|
35
|
+
class="h-full w-full"
|
|
36
|
+
viewBox="0 0 24 24"
|
|
37
|
+
fill="none"
|
|
38
|
+
stroke="currentColor"
|
|
39
|
+
stroke-width="3"
|
|
40
|
+
stroke-linecap="round"
|
|
41
|
+
stroke-linejoin="round"
|
|
42
|
+
aria-hidden="true"
|
|
43
|
+
>
|
|
44
|
+
<path d={checkIconPath} />
|
|
45
|
+
</svg>
|
|
46
|
+
)}
|
|
47
|
+
{checked === 'indeterminate' && (
|
|
48
|
+
<svg
|
|
49
|
+
class="h-full w-full"
|
|
50
|
+
viewBox="0 0 24 24"
|
|
51
|
+
fill="none"
|
|
52
|
+
stroke="currentColor"
|
|
53
|
+
stroke-width="3"
|
|
54
|
+
stroke-linecap="round"
|
|
55
|
+
stroke-linejoin="round"
|
|
56
|
+
aria-hidden="true"
|
|
57
|
+
>
|
|
58
|
+
<path d={indeterminateIconPath} />
|
|
59
|
+
</svg>
|
|
60
|
+
)}
|
|
61
|
+
{name && <input type="hidden" name={name} value={checked === 'indeterminate' ? 'indeterminate' : String(checked)} data-rfr-checkbox-input />}
|
|
62
|
+
</button>
|
|
63
|
+
|
|
64
|
+
<script>
|
|
65
|
+
document.querySelectorAll<HTMLButtonElement>('[data-rfr-checkbox]').forEach((el) => {
|
|
66
|
+
el.addEventListener('click', () => {
|
|
67
|
+
if (el.disabled) return
|
|
68
|
+
const currentState = el.getAttribute('aria-checked')
|
|
69
|
+
let newChecked: boolean
|
|
70
|
+
if (currentState === 'mixed') {
|
|
71
|
+
newChecked = true
|
|
72
|
+
} else {
|
|
73
|
+
newChecked = currentState !== 'true'
|
|
74
|
+
}
|
|
75
|
+
el.setAttribute('aria-checked', String(newChecked))
|
|
76
|
+
el.setAttribute('data-state', newChecked ? 'checked' : 'unchecked')
|
|
77
|
+
|
|
78
|
+
// Toggle check icon visibility
|
|
79
|
+
const svg = el.querySelector('svg')
|
|
80
|
+
if (newChecked) {
|
|
81
|
+
if (!svg) {
|
|
82
|
+
const newSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
83
|
+
newSvg.setAttribute('class', 'h-full w-full')
|
|
84
|
+
newSvg.setAttribute('viewBox', '0 0 24 24')
|
|
85
|
+
newSvg.setAttribute('fill', 'none')
|
|
86
|
+
newSvg.setAttribute('stroke', 'currentColor')
|
|
87
|
+
newSvg.setAttribute('stroke-width', '3')
|
|
88
|
+
newSvg.setAttribute('stroke-linecap', 'round')
|
|
89
|
+
newSvg.setAttribute('stroke-linejoin', 'round')
|
|
90
|
+
newSvg.setAttribute('aria-hidden', 'true')
|
|
91
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
|
92
|
+
path.setAttribute('d', 'M20 6L9 17l-5-5')
|
|
93
|
+
newSvg.appendChild(path)
|
|
94
|
+
// Insert before the hidden input if it exists, otherwise append
|
|
95
|
+
const input = el.querySelector('[data-rfr-checkbox-input]')
|
|
96
|
+
if (input) {
|
|
97
|
+
el.insertBefore(newSvg, input)
|
|
98
|
+
} else {
|
|
99
|
+
el.appendChild(newSvg)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
if (svg) svg.remove()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Update CSS variant classes for checked state
|
|
107
|
+
if (newChecked) {
|
|
108
|
+
el.classList.add('bg-primary', 'text-primary-foreground')
|
|
109
|
+
el.classList.remove('bg-background')
|
|
110
|
+
} else {
|
|
111
|
+
el.classList.remove('bg-primary', 'text-primary-foreground')
|
|
112
|
+
el.classList.add('bg-background')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Update hidden input
|
|
116
|
+
const input = el.querySelector('[data-rfr-checkbox-input]') as HTMLInputElement | null
|
|
117
|
+
if (input) input.value = String(newChecked)
|
|
118
|
+
|
|
119
|
+
el.dispatchEvent(new CustomEvent('change', { detail: { checked: newChecked } }))
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
el.addEventListener('keydown', (e) => {
|
|
123
|
+
if (e.key === ' ') {
|
|
124
|
+
e.preventDefault()
|
|
125
|
+
el.click()
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|