Recommended pattern for customizing Button sizes without affecting Calendar? #10788
Replies: 3 comments 1 reply
-
|
The issue is that Calendar (and other components) import The cleanest approach is to not modify the existing size variants, but add new custom ones instead. Keep If you really want to override the defaults, you'd need to also update every component that uses |
Beta Was this translation helpful? Give feedback.
-
|
The dependency is intentional by design — internal components like Calendar use Recommended Pattern: Add custom size variants, don't override defaultsIn your // components/ui/button.tsx
const buttonVariants = cva(
'inline-flex items-center justify-center ...',
{
variants: {
variant: {
default: '...',
// ...other variants
},
size: {
// Keep ALL original sizes intact for internal components
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
// Add YOUR custom sizes with different names
'app-default': 'h-10 px-4',
'app-sm': 'h-9 px-3',
'app-lg': 'h-11 px-5',
},
},
defaultVariants: {
variant: 'default',
size: 'default', // Calendar uses this default, leave it alone
},
}
);Then use your custom variants in your app code: // App buttons use your custom sizes
<Button size="app-default">Click me</Button>
<Button size="app-sm">Small</Button>
// Calendar still uses default/sm/icon internally — untouched
<Calendar />Alternative: Wrap Calendar with its own Button overrideIf you truly want to change what // components/calendar-wrapper.tsx
export function CalendarWrapper(props: React.ComponentProps<typeof Calendar>) {
return (
<div className="[&_.rdp-button]:h-9 [&_.rdp-button]:w-9 [&_.rdp-nav_button]:h-7 [&_.rdp-nav_button]:w-7">
<Calendar {...props} />
</div>
);
}This uses Tailwind's arbitrary variant selector to pin Calendar's internal button dimensions regardless of what Why this happensThe shadcn philosophy is that you own the component code — they're not a library you upgrade. So the recommended approach is: add to |
Beta Was this translation helpful? Give feedback.
-
|
The recommended pattern is to create a separate set of size variants for your app buttons while keeping the internal Option 1: Create an AppButton wrapper (cleanest) // components/ui/app-button.tsx
import { Button, type ButtonProps } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { cva } from 'class-variance-authority'
const appButtonSizes = cva('', {
variants: {
size: {
sm: 'h-9 px-3',
default: 'h-10 px-4',
lg: 'h-11 px-5',
},
},
defaultVariants: { size: 'default' },
})
export function AppButton({ size, className, ...props }: ButtonProps) {
return (
<Button
{...props}
size={null} // disable default sizing
className={cn(appButtonSizes({ size }), className)}
/>
}
}Option 2: Override at the CSS layer using Tailwind In your [data-slot='calendar'] button {
@apply h-7 w-7; /* keep calendar nav buttons small */
}Why not just edit You can, but every @dev-fatih-erol The wrapper approach is what most production shadcn projects use — it gives you a clean separation between your app's design system and shadcn's internal component composition. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I’m trying to customize the default
Buttonheight in my project.For example, I want my app buttons to use a different size scale like:
But I noticed that some shadcn components depend on Button / buttonVariants.
For example, in the Calendar component:
import { Button, buttonVariants } from "@/components/ui/button"The previous / next navigation buttons use:
buttonVariants({ variant: buttonVariant })and the day button uses:
<Button variant="ghost" size="icon" />So if I customize shared Button styles such as:
size.icon
variant.ghost
base focus/ring classes
transition/border classes
Calendar can also be affected.
Is this dependency intended?
What is the recommended design-system approach here?
Should I:
Keep the original shadcn Button variants/sizes stable and add app-specific sizes like app, appSm, appLg?
Create a separate AppButton component for product UI and keep shadcn Button only for internal shadcn components?
Detach components like Calendar from buttonVariants and give them their own internal styles?
I’m not asking how to patch Calendar specifically.
I’m trying to understand the recommended pattern for customizing Button sizes safely without having to manually check every component that might depend on buttonVariants.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions