Skip to content

Commit

Permalink
refactor(type): Move Button style edge case to theme
Browse files Browse the repository at this point in the history
The combination of `outline={true}` and `color="gray"`
triggers a set of special classes. So I set up the
API like so:

```js
outline: {
  base: '..',
  color: {
    gray: 'special case classes',
    ... any other special cases the user may need to accomodate
  },
  ..
}
```
  • Loading branch information
tulup-conner committed May 28, 2022
1 parent 223fac8 commit 9140a24
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/lib/components/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ describe('Components / Button', () => {

describe('Rendering', () => {
it('should render', () => {
const button = getButton(render(<Button>Hi there</Button>));
const button = getButton(
render(
<Button color="gray" outline>
Hi there
</Button>,
),
);

expect(button).toHaveTextContent('Hi there');
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const ButtonComponent: FC<ButtonComponentProps> = ({
return (
<button
className={classNames(
color === 'gray' && outline && 'border border-gray-900 dark:border-white',
disabled && theme.disabled,
!gradientDuoTone && !gradientMonochrome && theme.color[color],
gradientDuoTone && !gradientMonochrome && theme.gradientDuoTone[gradientDuoTone],
!gradientDuoTone && gradientMonochrome && theme.gradient[gradientMonochrome],
groupTheme.position[positionInGroup],
outline && theme.outline.color[color],
theme.base,
theme.pill[pill ? 'on' : 'off'],
)}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Flowbite/FlowbiteTheme.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AlertColors } from '../Alert';
import type { AvatarSizes } from '../Avatar';
import { ButtonColors, ButtonOutlineColors, ButtonSizes, PositionInButtonGroup } from '../Button';
import { ButtonColors, ButtonSizes, PositionInButtonGroup } from '../Button';
import { ButtonGradientColors, ButtonGradientDuoToneColors } from '../Button';

export type CustomFlowbiteTheme = DeepPartial<FlowbiteTheme>;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/theme/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export default {
label:
'ml-2 inline-flex h-4 w-4 items-center justify-center rounded-full bg-blue-200 text-xs font-semibold text-blue-800',
outline: {
color: {
gray: 'border border-gray-900 dark:border-white',
},
off: '',
on: 'bg-white text-gray-900 transition-all duration-75 ease-in group-hover:bg-opacity-0 group-hover:text-inherit dark:bg-gray-900 dark:text-white',
pill: {
Expand Down

0 comments on commit 9140a24

Please sign in to comment.