diff --git a/src/Containers/SquareTable/SquareTable.stories.tsx b/src/Containers/SquareTable/SquareTable.stories.tsx index eddd1335f..cfb40127b 100644 --- a/src/Containers/SquareTable/SquareTable.stories.tsx +++ b/src/Containers/SquareTable/SquareTable.stories.tsx @@ -2,22 +2,14 @@ import React from 'react'; import { Meta, Story } from '@storybook/react'; import { ISquareTable, SquareTable } from '@Containers'; - export default { title: 'Components/TableManagement/SquareTable', component: SquareTable, + argTypes: { onTableClick: {action: "Clicked table with index: "} }, } as Meta; const Template: Story = (args) => ; -/** - * Prints the Selected Child index to the console when Table is clicked - * @param selectedChildIndex - */ -const handleTableClick = (selectedChildIndex: number) => { - console.log(selectedChildIndex); -}; - /** * Prints the Selected Child index to the console when Chair is clicked * @param tableIndex @@ -144,7 +136,6 @@ SevenTopSquareTable.args = { ], isSquare: true, tableUse: 'TableForManagement', - onTableClick: handleTableClick, onChairClick: handleOnChairClick, }; @@ -257,7 +248,6 @@ EightTopVertRectangleTable.args = { ], isSquare: false, tableUse: 'TableForManagement', - onTableClick: handleTableClick, onChairClick: handleOnChairClick, }; @@ -347,7 +337,6 @@ SixTopHorizontalRectangleTable.args = { isSquare: false, relativeSize: 0.5, tableUse: 'TableForManagement', - onTableClick: handleTableClick, onChairClick: handleOnChairClick, }; @@ -410,7 +399,6 @@ SquareTableEditPage.args = { }, ], tableUse: 'TableForEditCanvas', - onTableClick: handleTableClick, onChairClick: handleOnChairClick, }; @@ -472,6 +460,5 @@ BarRectangleTable.args = { ], isSquare: false, tableUse: 'TableForManagement', - onTableClick: handleTableClick, onChairClick: handleOnChairClick, }; diff --git a/src/Containers/SquareTable/SquareTable.tsx b/src/Containers/SquareTable/SquareTable.tsx index cfca5f86f..d0a88f1a5 100644 --- a/src/Containers/SquareTable/SquareTable.tsx +++ b/src/Containers/SquareTable/SquareTable.tsx @@ -2,7 +2,7 @@ * Documentation – the order of chairs are in the chairs array will populate the table from top left to the bottom right * “the purpose of the order in the array is to populate the chairs from top left to bottom right” */ -import React, { useEffect, useRef } from 'react'; +import React, {useEffect, useRef, useState} from 'react'; import styled, { useTheme } from 'styled-components'; import { Plus } from '@styled-icons/boxicons-regular'; import { IChair } from '../Chair/Chair'; @@ -24,7 +24,7 @@ type getSquareTableSizeType = ( type getRectangleTableType = (top: number, bottom: number, left: number, right : number) => number; type addInvisibleChairs = ( - invisibileChairs: Array, + invisibleChairs: Array, targetSize: number, position: Position, ) => void; @@ -103,14 +103,11 @@ export interface ISquareTable { isNotHighlightedWhenSelected?: boolean; } - - /** * Primary UI component for user interaction * Square Table */ export const SquareTable: React.FC = ({ - // tableShape = 'Square', tableID = 'T1', partyName = 'Null', occupancyStatus = 'Vacant', @@ -120,7 +117,6 @@ export const SquareTable: React.FC = ({ isSquare = false, tableUse = 'TableForManagement', arrayIndex = 0, - selectedIndex = -1, onTableClick, onChairClick, isNotHighlightedWhenSelected = false, @@ -129,12 +125,14 @@ export const SquareTable: React.FC = ({ // Create a reference to the TableBody styled component const tableBodyRef = useRef(document.createElement('div')); + const [selectedTable, setSelectedTable] = useState(-1); + /** * Use useEffect to keep focus on TableBody after re-render if the * selectedIndex number matches the arrayIndex number for this table */ useEffect(() => { - if (selectedIndex === arrayIndex) { + if (selectedTable === arrayIndex) { if (tableBodyRef != null) { tableBodyRef.current.focus(); } @@ -166,8 +164,10 @@ export const SquareTable: React.FC = ({ * Calls the onTableClick prop function with the arrayIndex prop as its * parameter */ - const callOnTableClick: callOnTableClickType = () => + const callOnTableClick: callOnTableClickType = () => { onTableClick(arrayIndex); + setSelectedTable(arrayIndex); + } /** * Determines how many chairs to put per each side @@ -233,7 +233,7 @@ export const SquareTable: React.FC = ({ tableUse, chairIndex: invisibileChairs.length, tableIndex: arrayIndex, - selectedIndex, + selectedIndex: selectedTable, onChairClick, }); } @@ -296,14 +296,19 @@ export const SquareTable: React.FC = ({ }; return ( -
+ + {/** chairs top */} {/** table itself */} @@ -315,7 +320,7 @@ export const SquareTable: React.FC = ({ position="left" chairs={leftArray} tableUse={tableUse} - selectedIndex={selectedIndex} + selectedIndex={selectedTable} /> = ({ position="right" chairs={rightArray} tableUse={tableUse} - selectedIndex={selectedIndex} + selectedIndex={selectedTable} />
@@ -352,8 +357,9 @@ export const SquareTable: React.FC = ({ position="bottom" chairs={bottomArray} tableUse={tableUse} - selectedIndex={selectedIndex} + selectedIndex={selectedTable} /> + ); }; @@ -380,8 +386,36 @@ const getOccupancyColor: getOccupancyColorType = (occupancyStatus) => { }; /** - * variables for the styled components + * Variables for the styled components */ +interface ITableContainer { + relativeSize: number; + tableIndex: number; + selectedIndex: number; +} + +const TableContainer = styled.div` + ${({ selectedIndex, tableIndex, relativeSize, theme }):string => + { + const BASE_BORDER_RADIUS = 3; + const PADDING = 1.5; + + if(tableIndex === selectedIndex){ + return` + background-color: ${theme.colors.tableOutline.background}; + border-radius: ${BASE_BORDER_RADIUS * relativeSize}rem; + width: fit-content; + padding: ${PADDING * relativeSize}rem; + border-style: dashed; + border-color: ${theme.colors.tableOutline.border}; + `; + } + + return ``; + } + }; + +`; interface ITableBody { chairNumOnSide: number; diff --git a/src/Themes/MainTheme.ts b/src/Themes/MainTheme.ts index 05c6f13d1..fb99c7f61 100644 --- a/src/Themes/MainTheme.ts +++ b/src/Themes/MainTheme.ts @@ -37,6 +37,10 @@ export interface MainThemeInterface extends ThemeTemplateInterface { green: string; }; bannerBackgroundColor: string; + tableOutline: { + background: string; + border: string; + } }; } @@ -77,5 +81,9 @@ export const MainTheme: MainThemeInterface = { yellow: '#d1b306', green: '#09d106', }, + tableOutline: { + background: "#EDEEF5", + border: "#DDDFE5", + } }, };