Skip to content

Commit 26b4e24

Browse files
committed
Add dark mode
1 parent 04150ce commit 26b4e24

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/Spreadsheet.css

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.Spreadsheet {
22
--background-color: white;
33
--text-color: black;
4-
--readonly-text-color: #999;
4+
--readonly-text-color: rgba(0, 0, 0, 0.4);
55
--outline-color: #4285f4;
66
--outline-background-color: rgba(160, 195, 255, 0.2);
7-
--border-color: rgb(231, 231, 231);
8-
--header-background-color: #f5f5f5;
7+
--border-color: hsl(2deg, 0%, 91%);
8+
--header-background-color: rgba(0, 0, 0, 0.04);
99
--elevation: 0 2px 5px rgba(0, 0, 0, 0.4);
1010

1111
position: relative;
@@ -15,6 +15,14 @@
1515
display: inline-block;
1616
}
1717

18+
.Spreadsheet--dark-mode {
19+
--background-color: black;
20+
--text-color: white;
21+
--readonly-text-color: rgba(255, 255, 255, 0.4);
22+
--header-background-color: rgba(255, 255, 255, 0.04);
23+
--border-color: hsl(2deg, 0%, 19%);
24+
}
25+
1826
.Spreadsheet__active-cell {
1927
position: absolute;
2028
border: 2px solid var(--outline-color);
@@ -36,8 +44,7 @@
3644
cursor: cell;
3745
}
3846

39-
.Spreadsheet__cell,
40-
.Spreadsheet__cell input {
47+
.Spreadsheet__cell {
4148
outline: none;
4249
}
4350

@@ -82,6 +89,7 @@
8289

8390
.Spreadsheet__data-editor input {
8491
font: inherit;
92+
color: inherit;
8593
background: none;
8694
border: none;
8795
outline: none;

src/Spreadsheet.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export type Props<CellType extends Types.CellBase> = {
4242
data: Matrix.Matrix<CellType>;
4343
/** Class to be added to the spreadsheet element */
4444
className?: string;
45+
/** Use dark colors that complenent dark mode */
46+
darkMode?: boolean;
4547
/**
4648
* Instance of `FormulaParser` to be used by the Spreadsheet.
4749
* Defaults to: internal instance created by the component.
@@ -117,6 +119,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
117119
): React.ReactElement => {
118120
const {
119121
className,
122+
darkMode,
120123
columnLabels,
121124
rowLabels,
122125
hideColumnIndicators,
@@ -476,7 +479,9 @@ const Spreadsheet = <CellType extends Types.CellBase>(
476479
() => (
477480
<div
478481
ref={rootRef}
479-
className={classNames("Spreadsheet", className)}
482+
className={classNames("Spreadsheet", className, {
483+
"Spreadsheet--dark-mode": darkMode,
484+
})}
480485
onKeyPress={onKeyPress}
481486
onKeyDown={handleKeyDown}
482487
onMouseMove={handleMouseMove}
@@ -490,6 +495,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
490495
),
491496
[
492497
className,
498+
darkMode,
493499
onKeyPress,
494500
handleKeyDown,
495501
handleMouseMove,

src/stories/Spreadsheet.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export default {
2424
} as Meta<Props<StringCell>>;
2525

2626
export const Basic: Story<Props<StringCell>> = (props) => (
27-
<Spreadsheet {...props} data={props.data} />
27+
<Spreadsheet {...props} />
28+
);
29+
30+
export const DarkMode: Story<Props<StringCell>> = (props) => (
31+
<Spreadsheet {...props} darkMode />
2832
);
2933

3034
export const Controlled: Story<Props<StringCell>> = (props) => {

0 commit comments

Comments
 (0)