Skip to content

Commit 7a74c55

Browse files
committed
refactor(CCarousel, CDropdown, CNavbar, COffcanvas): update dark variants handling
1 parent a4688bb commit 7a74c55

File tree

13 files changed

+104
-57
lines changed

13 files changed

+104
-57
lines changed

packages/coreui-react/src/components/carousel/CCarousel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
226226
className={classNames(
227227
'carousel slide',
228228
{
229-
'carousel-dark': dark,
230229
'carousel-fade': transition === 'crossfade',
231230
},
232231
className,
233232
)}
233+
{...(dark && { 'data-coreui-theme': 'dark' })}
234234
onMouseEnter={_pause}
235235
onMouseLeave={cycle}
236236
{...(touch && { onTouchStart: handleTouchStart, onTouchMove: handleTouchMove })}

packages/coreui-react/src/components/close-button/CCloseButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ export interface CCloseButtonProps extends HTMLAttributes<HTMLButtonElement> {
77
* A string of all className you want applied to the base component.
88
*/
99
className?: string
10+
/**
11+
* Invert the default color.
12+
*/
13+
dark?: boolean
1014
/**
1115
* Toggle the disabled state for the component.
1216
*/
1317
disabled?: boolean
1418
/**
1519
* Change the default color to white.
20+
*
21+
* @deprecated 5.0.0
1622
*/
1723
white?: boolean
1824
}
1925

2026
export const CCloseButton = forwardRef<HTMLButtonElement, CCloseButtonProps>(
21-
({ className, disabled, white, ...rest }, ref) => {
27+
({ className, dark, disabled, white, ...rest }, ref) => {
2228
return (
2329
<button
2430
type="button"
@@ -33,6 +39,7 @@ export const CCloseButton = forwardRef<HTMLButtonElement, CCloseButtonProps>(
3339
)}
3440
aria-label="Close"
3541
disabled={disabled}
42+
{...(dark && { 'data-coreui-theme': 'dark' })}
3643
{...rest}
3744
ref={ref}
3845
/>
@@ -42,6 +49,7 @@ export const CCloseButton = forwardRef<HTMLButtonElement, CCloseButtonProps>(
4249

4350
CCloseButton.propTypes = {
4451
className: PropTypes.string,
52+
dark: PropTypes.bool,
4553
disabled: PropTypes.bool,
4654
white: PropTypes.bool,
4755
}

packages/coreui-react/src/components/dropdown/CDropdownMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const CDropdownMenu = forwardRef<HTMLDivElement | HTMLUListElement, CDrop
4646
className={classNames(
4747
'dropdown-menu',
4848
{
49-
'dropdown-menu-dark': dark,
5049
show: visible,
5150
},
5251
alignment && alignmentClassNames(alignment),
@@ -56,6 +55,7 @@ export const CDropdownMenu = forwardRef<HTMLDivElement | HTMLUListElement, CDrop
5655
role="menu"
5756
aria-hidden={!visible}
5857
{...(!popper && { 'data-coreui-popper': 'static' })}
58+
{...(dark && { 'data-coreui-theme': 'dark' })}
5959
{...rest}
6060
>
6161
{Component === 'ul'

packages/coreui-react/src/components/navbar/CNavbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface CNavbarProps extends HTMLAttributes<HTMLDivElement> {
1717
*/
1818
color?: Colors
1919
/**
20-
* Sets if the color of text should be colored for a light or dark dark background.
20+
* Sets if the color of text should be colored for a light or dark background.
2121
*/
2222
colorScheme?: 'dark' | 'light'
2323
/**
@@ -59,12 +59,12 @@ export const CNavbar = forwardRef<HTMLDivElement, CNavbarProps>(
5959
'navbar',
6060
{
6161
[`bg-${color}`]: color,
62-
[`navbar-${colorScheme}`]: colorScheme,
6362
[typeof expand === 'boolean' ? 'navbar-expand' : `navbar-expand-${expand}`]: expand,
6463
},
6564
placement,
6665
className,
6766
)}
67+
{...(colorScheme && { 'data-coreui-theme': colorScheme })}
6868
{...rest}
6969
ref={ref}
7070
>

packages/coreui-react/src/components/offcanvas/COffcanvas.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
1717
* A string of all className you want applied to the base component.
1818
*/
1919
className?: string
20+
/**
21+
* Sets a darker color scheme.
22+
*/
23+
dark?: boolean
2024
/**
2125
* Closes the offcanvas when escape key is pressed.
2226
*/
@@ -59,6 +63,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
5963
children,
6064
backdrop = true,
6165
className,
66+
dark,
6267
keyboard = true,
6368
onHide,
6469
onShow,
@@ -135,6 +140,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
135140
role="dialog"
136141
tabIndex={-1}
137142
onKeyDown={handleKeyDown}
143+
{...(dark && { 'data-coreui-theme': 'dark' })}
138144
{...rest}
139145
ref={forkedRef}
140146
>
@@ -161,6 +167,7 @@ COffcanvas.propTypes = {
161167
backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf<'static'>(['static'])]),
162168
children: PropTypes.node,
163169
className: PropTypes.string,
170+
dark: PropTypes.bool,
164171
keyboard: PropTypes.bool,
165172
onHide: PropTypes.func,
166173
onShow: PropTypes.func,

packages/docs/content/api/CCloseButton.api.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ import CCloseButton from '@coreui/react/src/components/close-button/CCloseButton
88
| Property | Description | Type | Default |
99
| --- | --- | --- | --- |
1010
| **className** | A string of all className you want applied to the base component. | `string` | - |
11+
| **dark** | Invert the default color. | `boolean` | - |
1112
| **disabled** | Toggle the disabled state for the component. | `boolean` | - |
12-
| **white** | Change the default color to white. | `boolean` | - |
13+
| **white** **_Deprecated 5.0.0+_** | Change the default color to white. | `boolean` | - |

packages/docs/content/api/CNavbar.api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CNavbar from '@coreui/react/src/components/navbar/CNavbar'
99
| --- | --- | --- | --- |
1010
| **className** | A string of all className you want applied to the component. | `string` | - |
1111
| **color** | Sets the color context of the component to one of CoreUI’s themed colors. | `'primary'` \| `'secondary'` \| `'success'` \| `'danger'` \| `'warning'` \| `'info'` \| `'dark'` \| `'light'` \| `string` | - |
12-
| **colorScheme** | Sets if the color of text should be colored for a light or dark dark background. | `'dark'` \| `'light'` | - |
12+
| **colorScheme** | Sets if the color of text should be colored for a light or dark background. | `'dark'` \| `'light'` | - |
1313
| **component** | Component used for the root node. Either a string to use a HTML element or a component. | `string` \| `ComponentClass<any, any>` \| `FunctionComponent<any>` | - |
1414
| **container** | Defines optional container wrapping children elements. | `boolean` \| `'sm'` \| `'md'` \| `'lg'` \| `'xl'` \| `'xxl'` \| `'fluid'` | - |
1515
| **expand** | Defines the responsive breakpoint to determine when content collapses. | `boolean` \| `'sm'` \| `'md'` \| `'lg'` \| `'xl'` \| `'xxl'` | - |

packages/docs/content/api/COffcanvas.api.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import COffcanvas from '@coreui/react/src/components/offcanvas/COffcanvas'
99
| --- | --- | --- | --- |
1010
| **backdrop** | Apply a backdrop on body while offcanvas is open. | `boolean` \| `'static'` | true |
1111
| **className** | A string of all className you want applied to the base component. | `string` | - |
12+
| **dark** | Sets a darker color scheme. | `boolean` | - |
1213
| **keyboard** | Closes the offcanvas when escape key is pressed. | `boolean` | true |
1314
| **onHide** | Callback fired when the component requests to be hidden. | `() => void` | - |
1415
| **onShow** | Callback fired when the component requests to be shown. | `() => void` | - |

packages/docs/content/api/CToastClose.api.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import CToastClose from '@coreui/react/src/components/toast/CToastClose'
1010
| **active** | Toggle the active state for the component. | `boolean` | - |
1111
| **className** | A string of all className you want applied to the base component. | `string` | - |
1212
| **component** | Component used for the root node. Either a string to use a HTML element or a component. | `string` \| `ComponentClass<any, any>` \| `FunctionComponent<any>` | - |
13+
| **dark** | Invert the default color. | `boolean` | - |
1314
| **disabled** | Toggle the disabled state for the component. | `boolean` | - |
1415
| **href** | The href attribute specifies the URL of the page the link goes to. | `string` | - |
1516
| **shape** | Select the shape of the component. | `'rounded'` \| `'rounded-top'` \| `'rounded-end'` \| `'rounded-bottom'` \| `'rounded-start'` \| `'rounded-circle'` \| `'rounded-pill'` \| `'rounded-0'` \| `'rounded-1'` \| `'rounded-2'` \| `'rounded-3'` \| `string` | - |
1617
| **size** | Size the component small or large. | `'sm'` \| `'lg'` | - |
1718
| **type** | Specifies the type of button. Always specify the type attribute for the `<button>` element.<br/>Different browsers may use different default types for the `<button>` element. | `'button'` \| `'submit'` \| `'reset'` | - |
1819
| **variant** | Set the button variant to an outlined button or a ghost button. | `'outline'` \| `'ghost'` | - |
19-
| **white** | Change the default color to white. | `boolean` | - |
20+
| **white** **_Deprecated 5.0.0+_** | Change the default color to white. | `boolean` | - |

packages/docs/content/components/close-button.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Disabled close buttons change their `opacity`. We've also applied `pointer-event
2525
<CCloseButton disabled />
2626
```
2727

28-
## White variant
28+
## Dark variant
2929

30-
Change the default `<CCloseButton>` to be white with the `white` boolean property.
30+
Add `dark` boolean property to the `<CCloseButton>`, to invert the close button. This uses the filter property to invert the background-image without overriding its value.
3131

3232
```jsx preview className="bg-dark border-0"
33-
<CCloseButton white />
34-
<CCloseButton white disabled />
33+
<CCloseButton dark />
34+
<CCloseButton dark disabled />
3535
```
3636

3737
## API

0 commit comments

Comments
 (0)