Skip to content

Commit 7da12c2

Browse files
author
iexitdev
committed
Polish docs combo toggles and realtime preview
1 parent ea3639d commit 7da12c2

4 files changed

Lines changed: 126 additions & 29 deletions

File tree

apps/site/src/previews/proPreviewComponents.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ export const RealtimeBarChartPreview = ({
571571
barRadius={3}
572572
barWidthRatio={0.82}
573573
data={rows}
574-
defaultSelectedBar={{ dataIndex: rows.length - 1, seriesKey: "users" }}
575574
formatXLabel={formatXLabel}
576575
formatYLabel={(value: number) => String(Math.round(value))}
577576
height={150}
@@ -635,13 +634,21 @@ export const ComboTogglePreview = ({
635634

636635
return (
637636
<View style={{ width: chartWidth }}>
638-
<View style={toggleStyles.toggleRow}>
637+
<View
638+
style={[
639+
toggleStyles.toggleRow,
640+
mode === "dark"
641+
? toggleStyles.toggleRowDark
642+
: toggleStyles.toggleRowLight
643+
]}
644+
>
639645
{items.map((item) => {
640646
const active = visibleSeriesKeys.includes(item.key);
641647

642648
return (
643649
<Pressable
644650
key={item.key}
651+
aria-pressed={active}
645652
accessibilityRole="button"
646653
onPress={() => {
647654
setVisibleSeriesKeys((currentKeys) => {
@@ -660,7 +667,11 @@ export const ComboTogglePreview = ({
660667
active && {
661668
backgroundColor: item.tint,
662669
borderColor: item.color
663-
}
670+
},
671+
active &&
672+
(mode === "dark"
673+
? toggleStyles.toggleActiveDark
674+
: toggleStyles.toggleActiveLight)
664675
]}
665676
>
666677
<View

apps/site/src/previews/toggleStyles.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,68 @@ export const toggleStyles = {
44
borderRadius: 999,
55
borderStyle: "solid" as const,
66
borderWidth: 1,
7+
display: "flex" as const,
78
flexDirection: "row" as const,
8-
gap: 6,
9+
gap: 5,
910
height: 28,
1011
justifyContent: "center" as const,
12+
minWidth: 88,
1113
paddingBottom: 0,
12-
paddingHorizontal: 10,
13-
paddingLeft: 10,
14-
paddingRight: 10,
14+
paddingHorizontal: 11,
15+
paddingLeft: 11,
16+
paddingRight: 11,
1517
paddingTop: 0
1618
},
1719
toggleDark: {
18-
backgroundColor: "rgba(255, 255, 255, 0.03)",
19-
borderColor: "rgba(255, 255, 255, 0.12)"
20+
backgroundColor: "transparent",
21+
borderColor: "transparent"
2022
},
2123
toggleLight: {
22-
backgroundColor: "rgba(16, 18, 23, 0.03)",
23-
borderColor: "rgba(16, 18, 23, 0.12)"
24+
backgroundColor: "transparent",
25+
borderColor: "transparent"
26+
},
27+
toggleActiveDark: {
28+
boxShadow: "0 6px 16px rgba(0, 0, 0, 0.18)"
29+
},
30+
toggleActiveLight: {
31+
boxShadow: "0 5px 14px rgba(7, 23, 51, 0.07)"
2432
},
2533
toggleRow: {
2634
alignItems: "center" as const,
35+
alignSelf: "flex-start" as const,
36+
borderRadius: 999,
37+
borderStyle: "solid" as const,
38+
borderWidth: 1,
39+
display: "flex" as const,
2740
flexDirection: "row" as const,
28-
flexWrap: "wrap" as const,
29-
gap: 8,
30-
marginBottom: 12
41+
gap: 2,
42+
marginBottom: 10,
43+
padding: 2
44+
},
45+
toggleRowDark: {
46+
backgroundColor: "rgba(255, 255, 255, 0.045)",
47+
borderColor: "rgba(255, 255, 255, 0.12)"
48+
},
49+
toggleRowLight: {
50+
backgroundColor: "rgba(7, 23, 51, 0.045)",
51+
borderColor: "rgba(7, 23, 51, 0.1)"
3152
},
3253
toggleSwatch: {
54+
borderColor: "rgba(255, 255, 255, 0.48)",
55+
borderStyle: "solid" as const,
56+
borderWidth: 1,
3357
borderRadius: 999,
34-
height: 7,
35-
width: 7
58+
height: 6,
59+
width: 6
3660
},
3761
toggleSwatchInactive: {
3862
opacity: 0.34
3963
},
4064
toggleText: {
41-
fontSize: 12,
42-
fontWeight: "600" as const,
65+
fontSize: 11,
66+
fontWeight: "700" as const,
4367
letterSpacing: 0,
44-
lineHeight: 14
68+
lineHeight: 13
4569
},
4670
toggleTextActiveDark: {
4771
color: "#f7f8f8"

docs/charts/combo.md

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ same x-axis.
111111
import { useState } from "react";
112112
import { Pressable, Text, View } from "react-native";
113113
import { ComboChart } from "@chart-kit/pro";
114+
import {
115+
resolveCartesianChartThemeConfig,
116+
useChartKitTheme
117+
} from "react-native-chart-kit/v2";
114118

115119
const money = (value: number) => `$${Math.round(value)}k`;
116120
const percent = (value: number) => `${Math.round(value)}%`;
@@ -130,10 +134,21 @@ const toggleItems = [
130134
{ key: "line-margin", label: "Margin" }
131135
];
132136

137+
const colorWithAlpha = (color: string, alpha: string) =>
138+
color.startsWith("#") && color.length === 7 ? `${color}${alpha}` : color;
139+
133140
export function ChannelPlan() {
134141
const [visibleSeriesKeys, setVisibleSeriesKeys] = useState(
135142
toggleItems.map((item) => item.key)
136143
);
144+
const chartKitTheme = useChartKitTheme();
145+
const resolvedTheme = resolveCartesianChartThemeConfig({
146+
mode: chartKitTheme.mode,
147+
preset: chartKitTheme.preset,
148+
presets: chartKitTheme.presets,
149+
theme: chartKitTheme.theme
150+
});
151+
const isLight = chartKitTheme.mode === "light";
137152

138153
const toggleSeries = (key: string) => {
139154
setVisibleSeriesKeys((currentKeys) => {
@@ -145,26 +160,73 @@ export function ChannelPlan() {
145160
});
146161
};
147162

163+
const seriesToggles = toggleItems.map((item, index) => ({
164+
...item,
165+
color: resolvedTheme.series[index] ?? "#2563eb"
166+
}));
167+
148168
return (
149-
<View>
150-
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8 }}>
151-
{toggleItems.map((item) => {
169+
<View style={{ width: 410 }}>
170+
<View
171+
style={{
172+
alignSelf: "flex-start",
173+
backgroundColor: isLight
174+
? "rgba(7, 23, 51, 0.045)"
175+
: "rgba(255, 255, 255, 0.055)",
176+
borderColor: resolvedTheme.grid,
177+
borderRadius: 999,
178+
borderWidth: 1,
179+
display: "flex",
180+
flexDirection: "row",
181+
gap: 2,
182+
marginBottom: 10,
183+
padding: 2
184+
}}
185+
>
186+
{seriesToggles.map((item) => {
152187
const active = visibleSeriesKeys.includes(item.key);
153188

154189
return (
155190
<Pressable
156191
key={item.key}
192+
aria-pressed={active}
157193
accessibilityRole="button"
158194
onPress={() => toggleSeries(item.key)}
159195
style={{
160-
borderColor: active ? "#2563eb" : "rgba(100, 116, 139, 0.32)",
196+
alignItems: "center",
197+
display: "flex",
198+
backgroundColor: active
199+
? colorWithAlpha(item.color, isLight ? "10" : "18")
200+
: "transparent",
201+
borderColor: active ? item.color : "transparent",
161202
borderRadius: 999,
162203
borderWidth: 1,
163-
paddingHorizontal: 10,
164-
paddingVertical: 5
204+
flexDirection: "row",
205+
gap: 5,
206+
height: 28,
207+
justifyContent: "center",
208+
minWidth: 88,
209+
paddingHorizontal: 11
165210
}}
166211
>
167-
<Text style={{ color: active ? "#2563eb" : "#64748b" }}>
212+
<View
213+
style={{
214+
backgroundColor: item.color,
215+
borderRadius: 999,
216+
height: 6,
217+
opacity: active ? 1 : 0.36,
218+
width: 6
219+
}}
220+
/>
221+
<Text
222+
numberOfLines={1}
223+
style={{
224+
color: active ? resolvedTheme.text : resolvedTheme.mutedText,
225+
fontSize: 11,
226+
fontWeight: "700",
227+
lineHeight: 13
228+
}}
229+
>
168230
{item.label}
169231
</Text>
170232
</Pressable>

docs/charts/realtime.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function ActiveUsersStream() {
6666
liveKey="pointIndex"
6767
windowSize={30}
6868
animation={{ duration: updateMs, mode: "slide" }}
69-
defaultSelectedBar={{ dataIndex: rows.length - 1, seriesKey: "users" }}
7069
interaction="tap"
7170
series={[{ yKey: "users", label: "Users", color: "#2563eb" }]}
7271
formatXLabel={(value) => {
@@ -101,8 +100,9 @@ Use `liveKey` whenever the incoming array is a rolling window. Selection keys ar
101100
based on that identity, so a selected bar can move left while its tooltip value
102101
stays attached to the same row.
103102

104-
`defaultSelectedBar` seeds the initial visible tooltip. `interaction="tap"` lets
105-
the user move selection without adding controlled state.
103+
Omit `defaultSelectedBar` when the stream should open idle. Add it only when the
104+
chart should seed an initial visible tooltip. `interaction="tap"` lets the user
105+
move selection without adding controlled state.
106106

107107
`tooltip={{ placement: "top" }}` pins the tooltip to the top of the chart while
108108
the x-position follows the selected bar.

0 commit comments

Comments
 (0)