Skip to content

Commit 626b7b2

Browse files
committed
refactor: add TextColors type
1 parent 2d69898 commit 626b7b2

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/components/Types.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export const shapePropType = PropTypes.oneOfType([
9494
PropTypes.string,
9595
])
9696

97+
export type TextColors = Colors | 'white' | 'muted' | string
98+
99+
export const textColorsPropType = PropTypes.oneOfType([
100+
colorPropType,
101+
PropTypes.oneOf(['white', 'muted']),
102+
PropTypes.string,
103+
])
104+
97105
export type Triggers = 'hover' | 'focus' | 'click'
98106

99107
export const triggerPropType = PropTypes.oneOf<Triggers>(['hover', 'focus', 'click'])

src/components/avatar/CAvatar.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import React, { forwardRef, HTMLAttributes } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

5-
import { Colors, Shapes, colorPropType, shapePropType } from '../Types'
5+
import {
6+
Colors,
7+
Shapes,
8+
TextColors,
9+
colorPropType,
10+
shapePropType,
11+
textColorsPropType,
12+
} from '../Types'
613

714
export interface CAvatarProps extends HTMLAttributes<HTMLDivElement> {
815
/**
@@ -37,8 +44,10 @@ export interface CAvatarProps extends HTMLAttributes<HTMLDivElement> {
3744
status?: Colors
3845
/**
3946
* Sets the text color of the component to one of CoreUI’s themed colors. [docs]
47+
*
48+
* @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | 'white' | 'muted' | string
4049
*/
41-
textColor?: string
50+
textColor?: TextColors
4251
}
4352

4453
export const CAvatar = forwardRef<HTMLDivElement, CAvatarProps>(
@@ -72,7 +81,7 @@ CAvatar.propTypes = {
7281
size: PropTypes.string,
7382
src: PropTypes.string,
7483
status: PropTypes.string,
75-
textColor: PropTypes.string,
84+
textColor: textColorsPropType,
7685
}
7786

7887
CAvatar.displayName = 'CAvatar'

src/components/badge/CBadge.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

5-
import { Colors, Shapes, colorPropType, shapePropType } from '../Types'
5+
import {
6+
Colors,
7+
Shapes,
8+
TextColors,
9+
colorPropType,
10+
shapePropType,
11+
textColorsPropType,
12+
} from '../Types'
613

714
export interface CBadgeProps extends HTMLAttributes<HTMLDivElement | HTMLSpanElement> {
815
/**
@@ -35,8 +42,10 @@ export interface CBadgeProps extends HTMLAttributes<HTMLDivElement | HTMLSpanEle
3542
size?: 'sm'
3643
/**
3744
* Sets the text color of the component to one of CoreUI’s themed colors. [docs]
45+
*
46+
* @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | 'white' | 'muted' | string
3847
*/
39-
textColor?: string
48+
textColor?: TextColors
4049
}
4150
export const CBadge = forwardRef<HTMLDivElement | HTMLSpanElement, CBadgeProps>(
4251
(
@@ -69,7 +78,7 @@ CBadge.propTypes = {
6978
component: PropTypes.string,
7079
shape: shapePropType,
7180
size: PropTypes.oneOf(['sm']),
72-
textColor: PropTypes.string,
81+
textColor: textColorsPropType,
7382
}
7483

7584
CBadge.displayName = 'CBadge'

0 commit comments

Comments
 (0)