Skip to content

Commit c425d8b

Browse files
authored
feat(style): support inverted prop (#418)
1 parent 23395c9 commit c425d8b

File tree

9 files changed

+84
-22
lines changed

9 files changed

+84
-22
lines changed

.storybook/preview-body.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<style>
2+
body {
3+
padding: 0 !important;
4+
}
5+
</style>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ More examples [here](https://react-semantic-ui-datepickers.now.sh).
103103
- error
104104
- iconPosition
105105
- id
106+
- inverted
106107
- label
107108
- loading
108109
- name
@@ -177,6 +178,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
177178

178179
<!-- markdownlint-enable -->
179180
<!-- prettier-ignore-end -->
181+
180182
<!-- ALL-CONTRIBUTORS-LIST:END -->
181183

182184
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

src/components/calendar/calendar.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import './calendar.css';
1111
interface CalendarProps extends RenderProps {
1212
filterDate: (date: Date) => boolean;
1313
inline: SemanticDatepickerProps['inline'];
14+
inverted: SemanticDatepickerProps['inverted'];
1415
maxDate?: Date;
1516
minDate?: Date;
1617
months: Locale['months'];
@@ -43,6 +44,7 @@ const Calendar: React.FC<CalendarProps> = ({
4344
getDateProps,
4445
getForwardProps,
4546
inline,
47+
inverted,
4648
maxDate,
4749
minDate,
4850
months,
@@ -56,6 +58,7 @@ const Calendar: React.FC<CalendarProps> = ({
5658
pointing,
5759
}) => (
5860
<Segment
61+
inverted={inverted}
5962
className={cn('clndr-calendars-segment', {
6063
'clndr-floating': !inline,
6164
[pointings[pointing]]: !inline,
@@ -73,11 +76,13 @@ const Calendar: React.FC<CalendarProps> = ({
7376
<Fragment>
7477
<Button
7578
icon="angle double left"
79+
inverted={inverted}
7680
title={previousYear}
7781
{...getBackProps({ calendars, offset: 12 })}
7882
/>
7983
<Button
8084
icon="angle left"
85+
inverted={inverted}
8186
style={{ marginRight: 0 }}
8287
title={previousMonth}
8388
{...getBackProps({ calendars })}
@@ -95,11 +100,13 @@ const Calendar: React.FC<CalendarProps> = ({
95100
<Fragment>
96101
<Button
97102
icon="angle right"
103+
inverted={inverted}
98104
title={nextMonth}
99105
{...getForwardProps({ calendars })}
100106
/>
101107
<Button
102108
icon="angle double right"
109+
inverted={inverted}
103110
style={{ marginRight: 0 }}
104111
title={nextYear}
105112
{...getForwardProps({ calendars, offset: 12 })}
@@ -112,6 +119,7 @@ const Calendar: React.FC<CalendarProps> = ({
112119
{weekdays.map((weekday) => (
113120
<CalendarCell
114121
key={`${calendar.year}-${calendar.month}-${weekday}`}
122+
inverted={inverted}
115123
title={weekday}
116124
>
117125
{weekday.slice(0, 2)}
@@ -122,7 +130,7 @@ const Calendar: React.FC<CalendarProps> = ({
122130
const key = `${calendar.year}-${calendar.month}-${weekIdx}`;
123131

124132
if (!dateObj) {
125-
return <CalendarCell key={key} />;
133+
return <CalendarCell key={key} inverted={inverted} />;
126134
}
127135

128136
const selectable =
@@ -135,6 +143,7 @@ const Calendar: React.FC<CalendarProps> = ({
135143
{...dateObj}
136144
{...getDateProps({ dateObj: { ...dateObj, selectable } })}
137145
data-testid={`datepicker-cell-${shortDate}`}
146+
inverted={inverted}
138147
selectable={selectable}
139148
>
140149
{dateObj.date.getDate()}
@@ -148,6 +157,7 @@ const Calendar: React.FC<CalendarProps> = ({
148157
</div>
149158
{showToday && (
150159
<TodayButton
160+
inverted={inverted}
151161
{...getToday(minDate, maxDate)}
152162
{...getDateProps({
153163
dateObj: getToday(minDate, maxDate),

src/components/cell/cell.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
cursor: pointer;
77
}
88

9+
.clndr-cell.inverted {
10+
background-color: #4f4f4f;
11+
}
12+
13+
.clndr-cell.inverted:hover {
14+
background-color: #757575;
15+
color: inherit;
16+
}
17+
918
.clndr-cell:hover {
1019
background-color: #cacbcd;
1120
color: inherit;
@@ -20,6 +29,11 @@
2029
color: inherit;
2130
}
2231

32+
.clndr-cell-inrange.inverted {
33+
background-color: #757575;
34+
color: inherit;
35+
}
36+
2337
.clndr-cell-disabled {
2438
cursor: default;
2539
opacity: 0.45;
@@ -29,11 +43,25 @@
2943
background-color: white;
3044
}
3145

46+
.clndr-cell-disabled.inverted:hover {
47+
background-color: #4f4f4f;
48+
color: inherit;
49+
}
50+
3251
.clndr-cell-selected {
3352
background-color: #4f4f4f;
3453
color: #f2f2f2;
3554
}
3655

56+
.clndr-cell-selected.inverted {
57+
background-color: white;
58+
color: black;
59+
}
60+
3761
.clndr-cell-other-month {
3862
color: #d9d9d9;
3963
}
64+
65+
.clndr-cell-other-month.inverted {
66+
color: #a6a6a6;
67+
}

src/components/cell/cell.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type CalendarCellProps = {
66
end?: boolean;
77
hovered?: boolean;
88
inRange?: boolean;
9+
inverted?: boolean;
910
nextMonth?: boolean;
1011
prevMonth?: boolean;
1112
selectable?: boolean;
@@ -19,6 +20,7 @@ const CalendarCell: React.FC<CalendarCellProps> = ({
1920
end,
2021
hovered,
2122
inRange,
23+
inverted,
2224
nextMonth,
2325
prevMonth,
2426
selectable,
@@ -29,6 +31,7 @@ const CalendarCell: React.FC<CalendarCellProps> = ({
2931
}) => (
3032
<span
3133
className={cn('clndr-cell', {
34+
inverted,
3235
'clndr-cell-today': today,
3336
'clndr-cell-disabled': !selectable,
3437
'clndr-cell-other-month': nextMonth || prevMonth,

src/components/today-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { DateObj } from 'dayzed';
3-
import { Button } from 'semantic-ui-react';
3+
import { Button, ButtonProps } from 'semantic-ui-react';
44

5-
interface TodayButtonProps extends DateObj {
5+
interface TodayButtonProps extends DateObj, ButtonProps {
66
end?: boolean;
77
hovered?: boolean;
88
inRange?: boolean;

src/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SemanticDatepicker extends React.Component<
6969
SemanticDatepickerProps,
7070
SemanticDatepickerState
7171
> {
72-
static defaultProps = {
72+
static defaultProps: SemanticDatepickerProps = {
7373
allowOnlyNumbers: false,
7474
clearIcon: 'close',
7575
clearOnSameDateClick: true,
@@ -97,6 +97,7 @@ class SemanticDatepicker extends React.Component<
9797
showOutsideDays: false,
9898
type: 'basic',
9999
value: null,
100+
inverted: false,
100101
};
101102

102103
el = React.createRef<HTMLDivElement>();
@@ -428,6 +429,7 @@ class SemanticDatepicker extends React.Component<
428429
pointing,
429430
filterDate,
430431
inline,
432+
inverted,
431433
readOnly,
432434
datePickerOnly,
433435
} = this.props;
@@ -445,6 +447,7 @@ class SemanticDatepicker extends React.Component<
445447
{...props}
446448
{...locale}
447449
filterDate={filterDate}
450+
inverted={inverted}
448451
pointing={pointing}
449452
weekdays={this.weekdays}
450453
/>

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type SemanticDatepickerProps = PickedDayzedProps &
6868
keepOpenOnSelect: boolean;
6969
icon?: SemanticICONS | React.ReactElement;
7070
inline: boolean;
71+
inverted: boolean;
7172
locale: LocaleOptions;
7273
onBlur: (event?: React.SyntheticEvent) => void;
7374
onChange: (

stories/index.stories.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { boolean, date, number, select, text } from '@storybook/addon-knobs';
3-
import { Form, SemanticICONS } from 'semantic-ui-react';
3+
import { Form, SemanticICONS, Table } from 'semantic-ui-react';
44
import 'semantic-ui-css/semantic.min.css';
55
import SemanticDatepicker from '../src';
66
import { SemanticDatepickerProps } from '../src/types';
@@ -107,24 +107,34 @@ export const withCustomIcons = () => {
107107
);
108108
};
109109

110-
export const usageWithForm = () => {
110+
export const usageWithForm = () => (
111+
<Content>
112+
<Form>
113+
<Form.Group width="equals">
114+
<SemanticDatepicker
115+
label="Initial date"
116+
id="initialDate"
117+
onChange={onChange}
118+
required
119+
/>
120+
<SemanticDatepicker
121+
label="Final date"
122+
id="finalDate"
123+
onChange={onChange}
124+
/>
125+
</Form.Group>
126+
</Form>
127+
</Content>
128+
);
129+
130+
export const inverted = () => {
131+
const type = select('Type', typeMap, typeMap.basic);
132+
111133
return (
112-
<Content>
113-
<Form>
114-
<Form.Group width="equals">
115-
<SemanticDatepicker
116-
label="Initial date"
117-
id="initialDate"
118-
onChange={onChange}
119-
required
120-
/>
121-
<SemanticDatepicker
122-
label="Final date"
123-
id="finalDate"
124-
onChange={onChange}
125-
/>
126-
</Form.Group>
127-
</Form>
134+
<Content style={{ padding: 20 }}>
135+
<Table inverted style={{ margin: 20, padding: 20 }}>
136+
<SemanticDatepicker inverted onChange={onChange} type={type} />
137+
</Table>
128138
</Content>
129139
);
130140
};

0 commit comments

Comments
 (0)