Skip to content

Commit 150d0b4

Browse files
authored
Merge pull request #542 from facultyai/default-colors
Fix default colours for Alert and Badge
2 parents fca3712 + b1d64fe commit 150d0b4

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

dash_bootstrap_components/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44

5+
from dash_bootstrap_components import themes # noqa
56
from dash_bootstrap_components import _components
67
from dash_bootstrap_components._components import * # noqa
78
from dash_bootstrap_components._table import _generate_table_from_df

src/components/Alert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const Alert = props => {
6060
};
6161

6262
Alert.defaultProps = {
63+
color: 'success',
6364
is_open: true,
6465
duration: null
6566
};

src/components/Badge.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Badge = props => {
4848
};
4949

5050
Badge.defaultProps = {
51+
color: 'secondary',
5152
n_clicks: 0,
5253
n_clicks_timestamp: -1
5354
};

src/components/__tests__/Alert.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ describe('Alert', () => {
2424
});
2525

2626
test('applies contextual colors with "color" prop', () => {
27+
const {
28+
container: {firstChild: alertSuccess}
29+
} = render(<Alert />);
2730
const {
2831
container: {firstChild: alertPrimary}
2932
} = render(<Alert color="primary" />);
3033
const {
31-
container: {firstChild: alertSuccess}
32-
} = render(<Alert color="success" />);
34+
container: {firstChild: alertDanger}
35+
} = render(<Alert color="danger" />);
3336
const {
3437
container: {firstChild: alertDark}
3538
} = render(<Alert color="dark" />);
3639

37-
expect(alertPrimary).toHaveClass('alert-primary');
3840
expect(alertSuccess).toHaveClass('alert-success');
41+
expect(alertPrimary).toHaveClass('alert-primary');
42+
expect(alertDanger).toHaveClass('alert-danger');
3943
expect(alertDark).toHaveClass('alert-dark');
4044
});
4145

src/components/__tests__/Badge.test.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ describe('Badge', () => {
1717
});
1818

1919
test('applies contextual colors with "color" prop', () => {
20+
const {
21+
container: {firstChild: badgeSecondary}
22+
} = render(<Badge />);
2023
const {
2124
container: {firstChild: badgePrimary}
2225
} = render(<Badge color="primary" />);
@@ -27,6 +30,7 @@ describe('Badge', () => {
2730
container: {firstChild: badgeDark}
2831
} = render(<Badge color="dark" />);
2932

33+
expect(badgeSecondary).toHaveClass('badge-secondary');
3034
expect(badgePrimary).toHaveClass('badge-primary');
3135
expect(badgeSuccess).toHaveClass('badge-success');
3236
expect(badgeDark).toHaveClass('badge-dark');
@@ -60,33 +64,31 @@ describe('Badge', () => {
6064
expect(mockSetProps.mock.calls[0][0].n_clicks).toBe(1);
6165
});
6266

63-
test('relative links are internal by default', () => {
64-
const badge = render(
65-
<Badge href="/relative">Clickable</Badge>
66-
);
67-
68-
const mockEventListener = jest.fn();
69-
window.addEventListener('_dashprivate_pushstate', mockEventListener);
70-
window.scrollTo = jest.fn();
71-
72-
expect(mockEventListener.mock.calls).toHaveLength(0);
73-
userEvent.click(badge.getByText('Clickable'));
74-
expect(mockEventListener.mock.calls).toHaveLength(1);
75-
});
76-
77-
test('relative links are external with external_link=true', () => {
78-
const badge = render(
79-
<Badge href="/relative" external_link>
80-
Clickable
81-
</Badge>
82-
);
83-
84-
const mockEventListener = jest.fn();
85-
window.addEventListener('_dashprivate_pushstate', mockEventListener);
86-
window.scrollTo = jest.fn();
87-
88-
expect(mockEventListener.mock.calls).toHaveLength(0);
89-
userEvent.click(badge.getByText('Clickable'));
90-
expect(mockEventListener.mock.calls).toHaveLength(0);
91-
});
67+
test('relative links are internal by default', () => {
68+
const badge = render(<Badge href="/relative">Clickable</Badge>);
69+
70+
const mockEventListener = jest.fn();
71+
window.addEventListener('_dashprivate_pushstate', mockEventListener);
72+
window.scrollTo = jest.fn();
73+
74+
expect(mockEventListener.mock.calls).toHaveLength(0);
75+
userEvent.click(badge.getByText('Clickable'));
76+
expect(mockEventListener.mock.calls).toHaveLength(1);
77+
});
78+
79+
test('relative links are external with external_link=true', () => {
80+
const badge = render(
81+
<Badge href="/relative" external_link>
82+
Clickable
83+
</Badge>
84+
);
85+
86+
const mockEventListener = jest.fn();
87+
window.addEventListener('_dashprivate_pushstate', mockEventListener);
88+
window.scrollTo = jest.fn();
89+
90+
expect(mockEventListener.mock.calls).toHaveLength(0);
91+
userEvent.click(badge.getByText('Clickable'));
92+
expect(mockEventListener.mock.calls).toHaveLength(0);
93+
});
9294
});

0 commit comments

Comments
 (0)