Skip to content

Commit 08888a9

Browse files
committed
feat: easier styling for tabs
1 parent ee4acc9 commit 08888a9

File tree

9 files changed

+426
-141
lines changed

9 files changed

+426
-141
lines changed

.storybook/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config: StorybookConfig = {
66
"@storybook/addon-essentials",
77
"@storybook/addon-interactions",
88
"@storybook/addon-webpack5-compiler-swc",
9+
"storybook-dark-mode",
910
],
1011
framework: {
1112
name: "@storybook/react-webpack5",

.storybook/preview.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { themes } from "@storybook/theming";
2+
13
import type { Preview } from "@storybook/react";
24

35
const preview: Preview = {
@@ -9,6 +11,14 @@ const preview: Preview = {
911
},
1012
},
1113
},
14+
// @ts-expect-error
15+
darkMode: {
16+
current: "dark",
17+
// Override the default dark theme
18+
dark: { ...themes.dark, appBg: "black" },
19+
// Override the default light theme
20+
light: { ...themes.normal, appBg: "red" },
21+
},
1222
};
1323

1424
export default preview;

README.md

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,14 @@ import { InstallCommand } from 'react-install-command';
160160
### Customization
161161

162162
```tsx
163-
// Custom prefix and copy icon
164-
<InstallCommand
165-
packageName="your-package"
166-
commandPrefix=""
167-
copyIcon={() => (
168-
<Icon
169-
icon="lucide:clipboard-copy"
170-
width={24}
171-
height={24}
172-
aria-label="Copy to clipboard"
173-
/>
174-
)}
175-
/>
176-
177163
// Custom class names
178164
<InstallCommand
179165
packageName="your-package"
180166
slotClassNames={{
181167
root: "custom-root",
182168
navigation: "custom-nav",
183169
tab: "custom-tab",
170+
tabIndicator: "install-block-tab-indicator-centered", // Centered indicator
184171
commandContainer: "custom-container",
185172
commandPrefix: "custom-prefix",
186173
commandText: "custom-text",
@@ -193,41 +180,70 @@ import { InstallCommand } from 'react-install-command';
193180
}}
194181
/>
195182

196-
// Full slot customization
183+
// Full customization with CSS classes
197184
<InstallCommand
198185
packageName="your-package"
199-
slots={{
200-
root: ({ children, className }) => (
201-
<div className={className} style={{ border: "2px solid purple" }}>
202-
{children}
203-
</div>
204-
),
205-
navigation: ({ children }) => (
206-
<nav style={{ background: "#f0f0f0", padding: "8px" }}>{children}</nav>
207-
),
208-
tab: ({ children, isSelected, onClick }) => (
209-
<button
210-
onClick={onClick}
211-
style={{
212-
background: isSelected ? "purple" : "transparent",
213-
color: isSelected ? "white" : "black"
214-
}}
215-
>
216-
{children}
217-
</button>
218-
),
219-
commandContainer: ({ children }) => (
220-
<div style={{ padding: "16px", background: "#fafafa" }}>{children}</div>
221-
),
222-
commandPrefix: () => <span style={{ color: "purple" }}>$</span>,
223-
commandText: ({ children }) => (
224-
<code style={{ color: "purple" }}>{children}</code>
225-
),
226-
copyButton: ({ onClick }) => (
227-
<button onClick={onClick} style={{ background: "purple", color: "white" }}>
228-
Copy
229-
</button>
230-
)
186+
slotClassNames={{
187+
root: "border-2 border-purple-500 rounded-lg",
188+
navigation: "bg-gray-100 p-2",
189+
tab: "bg-transparent hover:bg-purple-50 text-black data-[state=active]:bg-purple-500 data-[state=active]:text-white px-2 py-1 mx-1 rounded",
190+
tabIndicator: "install-block-tab-indicator-gradient", // Gradient indicator
191+
commandContainer: "p-4 bg-gray-50",
192+
commandPrefix: "text-purple-500",
193+
commandText: "text-purple-500 font-mono",
194+
copyButton: "bg-purple-500 text-white px-2 py-1 rounded border-0"
195+
}}
196+
/>
197+
```
198+
199+
### Built-in Indicator Variants
200+
201+
The component comes with several built-in indicator variants that you can use:
202+
203+
1. Default indicator (full width):
204+
```tsx
205+
<InstallCommand packageName="your-package" />
206+
```
207+
208+
2. Centered indicator:
209+
```tsx
210+
<InstallCommand
211+
packageName="your-package"
212+
slotClassNames={{
213+
tabIndicator: "install-block-tab-indicator-centered"
214+
}}
215+
/>
216+
```
217+
218+
3. Gradient indicator:
219+
```tsx
220+
<InstallCommand
221+
packageName="your-package"
222+
slotClassNames={{
223+
tabIndicator: "install-block-tab-indicator-gradient"
224+
}}
225+
/>
226+
```
227+
228+
You can also create your own indicator styles by extending these classes or creating new ones in your CSS:
229+
230+
```css
231+
.my-custom-indicator {
232+
left: 15%;
233+
width: 70%;
234+
height: 3px;
235+
border-radius: 1.5px;
236+
background: linear-gradient(90deg, var(--primary), var(--accent));
237+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
238+
}
239+
```
240+
241+
Then use it in your component:
242+
```tsx
243+
<InstallCommand
244+
packageName="your-package"
245+
slotClassNames={{
246+
tabIndicator: "my-custom-indicator"
231247
}}
232248
/>
233249
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@storybook/react": "8.4.7",
9696
"@storybook/react-webpack5": "8.4.7",
9797
"@storybook/test": "8.4.7",
98+
"@storybook/theming": "^8.5.5",
9899
"@testing-library/jest-dom": "6.6.3",
99100
"@testing-library/react": "16.1.0",
100101
"@types/node": "22.10.5",
@@ -111,6 +112,7 @@
111112
"react-test-renderer": "18.3.1",
112113
"release-it": "17.11.0",
113114
"storybook": "8.4.7",
115+
"storybook-dark-mode": "^4.0.2",
114116
"ts-node": "10.9.2",
115117
"tsconfig-paths": "4.2.0",
116118
"tsup": "8.3.5",
@@ -128,7 +130,6 @@
128130
}
129131
},
130132
"dependencies": {
131-
"@types/html2canvas": "^1.0.0",
132133
"html2canvas": "^1.4.1"
133134
}
134135
}

pnpm-lock.yaml

Lines changed: 42 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)