Skip to content

Commit 781d525

Browse files
committed
feat(grid): rename layout to position and add styling interface for grid items
1 parent ff87c97 commit 781d525

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

electron/renderer/components/grid/grid-item.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { memo, useCallback, useMemo, useRef } from 'react';
2424
import type {
2525
GridItemBoundary,
2626
GridItemInfo,
27-
GridItemLayout,
27+
GridItemPosition,
2828
} from '../../types/grid.types.js';
2929

3030
export interface GridItemProps {
@@ -36,7 +36,7 @@ export interface GridItemProps {
3636
* The positional layout for the grid item.
3737
* If not specified then a default location will be used.
3838
*/
39-
layout?: GridItemLayout;
39+
position?: GridItemPosition;
4040
/**
4141
* The unique identifier for the grid item.
4242
*/
@@ -74,7 +74,7 @@ export interface GridItemProps {
7474
children?: ReactNode;
7575
}
7676

77-
const DEFAULT_GRID_ITEM_LAYOUT: GridItemLayout = {
77+
const DEFAULT_GRID_ITEM_POSITION: GridItemPosition = {
7878
x: 0,
7979
y: 0,
8080
width: 500,
@@ -84,16 +84,17 @@ const DEFAULT_GRID_ITEM_LAYOUT: GridItemLayout = {
8484
export const GridItem: React.FC<GridItemProps> = memo(
8585
(props: GridItemProps): ReactNode => {
8686
const { itemId, itemTitle, isFocused = false, children } = props;
87-
const { boundary, layout = DEFAULT_GRID_ITEM_LAYOUT } = props;
87+
const { boundary, position = DEFAULT_GRID_ITEM_POSITION } = props;
8888
const { onFocus, onClose, onMoveResize } = props;
8989

9090
const { euiTheme } = useEuiTheme();
9191

9292
// Set default position and size for the grid item.
9393
// Like `useState`, we can provide the default value, but as a function.
94-
const [{ x, y, width, height }, sizeApi] = useSpring<GridItemLayout>(() => {
95-
return layout;
96-
}, [layout]);
94+
const [{ x, y, width, height }, sizeApi] =
95+
useSpring<GridItemPosition>(() => {
96+
return position;
97+
}, [position]);
9798

9899
const dragHandleRef = useRef<HTMLDivElement>(null);
99100
const resizeHandleRef = useRef<HTMLDivElement>(null);
@@ -103,7 +104,7 @@ export const GridItem: React.FC<GridItemProps> = memo(
103104
itemId,
104105
itemTitle,
105106
isFocused,
106-
layout: {
107+
position: {
107108
x: x.get(),
108109
y: y.get(),
109110
width: width.get(),

electron/renderer/components/grid/grid.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export const Grid: React.FC<GridProps> = (props: GridProps): ReactNode => {
5555
logger.debug('moved item', { item });
5656
publish('layout:item:moved', {
5757
itemId: item.itemId,
58-
x: item.layout.x,
59-
y: item.layout.y,
60-
width: item.layout.width,
61-
height: item.layout.height,
58+
x: item.position.x,
59+
y: item.position.y,
60+
width: item.position.width,
61+
height: item.position.height,
6262
});
6363
},
6464
[logger, publish]
@@ -72,7 +72,7 @@ export const Grid: React.FC<GridProps> = (props: GridProps): ReactNode => {
7272
itemId={contentItem.itemId}
7373
itemTitle={contentItem.itemTitle}
7474
isFocused={contentItem.itemId === focusedItemId}
75-
layout={contentItem.layout}
75+
position={contentItem.position}
7676
boundary={boundary}
7777
onFocus={onItemFocus}
7878
onClose={onItemClose}

electron/renderer/types/grid.types.ts

+35-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface GridItemInfo {
1515
itemId: string;
1616
itemTitle: string;
1717
isFocused: boolean;
18-
layout: GridItemLayout;
18+
position: GridItemPosition;
1919
}
2020

2121
export interface GridItemConfig {
@@ -36,7 +36,11 @@ export interface GridItemConfig {
3636
/**
3737
* The initial position for the grid item.
3838
*/
39-
layout: GridItemLayout;
39+
position: GridItemPosition;
40+
/**
41+
* The styling for the grid item.
42+
*/
43+
style: GridItemStyle;
4044
/**
4145
* When this item is not visible, redirect its content to another item.
4246
* If that item is also not visible, then it continues to be redirected
@@ -62,7 +66,7 @@ export interface GridItemBoundary {
6266
/**
6367
* The positional layout for the grid item.
6468
*/
65-
export interface GridItemLayout {
69+
export interface GridItemPosition {
6670
/**
6771
* The x coordinate for the grid item.
6872
* The leftmost edge of the grid item.
@@ -86,3 +90,31 @@ export interface GridItemLayout {
8690
*/
8791
height: number;
8892
}
93+
94+
/**
95+
* The font styling for the grid item.
96+
*/
97+
export interface GridItemStyle {
98+
/**
99+
* The font family to use for the text.
100+
* For example, "Verdana" or "Courier New".
101+
*/
102+
textFont: string;
103+
/**
104+
* The font size to use for the text, in pixels.
105+
* For example, 12.
106+
*/
107+
textSize: number;
108+
/**
109+
* The color name or hex code to use for the text.
110+
* For example, "red" or "#FF0000".
111+
* Though any valid CSS color value will work.
112+
*/
113+
foregroundColor: string;
114+
/**
115+
* The color name or hex code to use for the background.
116+
* For example, "blue" or "#0000FF".
117+
* Though any valid CSS color value will work.
118+
*/
119+
backgroundColor: string;
120+
}

0 commit comments

Comments
 (0)