Skip to content

Commit

Permalink
feat: wp
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Feb 15, 2025
1 parent 61bfd06 commit 072a607
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .storybook/manager.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#storybook-root {
width: 100% !important;
}

3 changes: 3 additions & 0 deletions .storybook/preview.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#storybook-root, .sb-show-main {
width: 100% !important;
}
3 changes: 2 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Preview } from '@storybook/react';
import React from 'react';

import { system } from '../src/ui/theme/theme';
import './preview.css'

const preview: Preview = {
parameters: {
Expand All @@ -18,7 +19,7 @@ const preview: Preview = {
decorators: [
Story => (
<ChakraProvider value={system}>
<Story />
<Story w='100%' className='preview-story'/>
</ChakraProvider>
),
withThemeByClassName({
Expand Down
45 changes: 29 additions & 16 deletions src/common/components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ const fixedFirstColumnCss = {
top: 0,
width: '2px',
height: 'full',
backgroundColor: 'newBorderPrimary',
backgroundColor: 'redesignBorderPrimary',
},
'.has-horizontal-scroll &:first-of-type::before': {
content: '""',
position: 'absolute',
right: 0,
width: '2px',
backgroundColor: 'redesignBorderPrimary',
top: '-8px', // Accounts for gap between header rows and the other rows
height: 'calc(calc(100%) + 8px)',
},
'&': {
position: 'sticky',
Expand Down Expand Up @@ -91,6 +100,7 @@ export function TableHeader<R, V = R[keyof R]>({
setSortColumnId,
setSortOrder,
hasFixedFirstColumn,
numColumns,
}: {
sortColumn?: string | null;
sortOrder?: SortOrder;
Expand All @@ -100,12 +110,13 @@ export function TableHeader<R, V = R[keyof R]>({
setSortColumnId: (columnId: string) => void;
setSortOrder: (sortOrder: SortOrder | undefined) => void;
hasFixedFirstColumn?: boolean;
numColumns: number;
}) {
const isFirstColumn = columnIndex === 0;

Check warning on line 115 in src/common/components/table/Table.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/table/Table.tsx#L114-L115

Added lines #L114 - L115 were not covered by tests
return (
<ChakraTable.ColumnHeader
py={3}
px={6}
px={[2, 2, 2, `clamp(12px, calc(48px / ${numColumns}), 16px)`]}
border="none"
borderBottom="1px solid var(--stacks-colors-surface-secondary)"
css={hasFixedFirstColumn && isFirstColumn ? fixedFirstColumnCss : {}}
Expand Down Expand Up @@ -133,18 +144,18 @@ export function TableHeader<R, V = R[keyof R]>({
whiteSpace="nowrap"
fontSize="sm"
color={{
_light: 'slate.700',
_dark: 'slate.250',
}}
textTransform="none"
letterSpacing="normal"
fontFamily="instrument"
css={{
'& .column-header-content:hover': {
color: 'textPrimary',
},
}}
>
_light: 'slate.700',
_dark: 'slate.250',
}}
textTransform="none"
letterSpacing="normal"
fontFamily="instrument"
css={{
'& .column-header-content:hover': {
color: 'textPrimary',
},
}}
>
{headerTitle}
</Text>
) : (
Expand Down Expand Up @@ -201,8 +212,8 @@ export function TableRow<R, V = R[keyof R]>({
return (

Check warning on line 212 in src/common/components/table/Table.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/table/Table.tsx#L210-L212

Added lines #L210 - L212 were not covered by tests
<ChakraTable.Cell
key={`table-row-${rowIndex}-col-${colIndex}`}
py={4}
px={6}
py={3}
px={[2, 2, 2, `clamp(12px, calc(48px / ${columnDefinitions.length}), 16px)`]}
css={{
...(hasFixedFirstColumn && isFirstColumn
? {

Check warning on line 219 in src/common/components/table/Table.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/table/Table.tsx#L219

Added line #L219 was not covered by tests
Expand Down Expand Up @@ -342,6 +353,7 @@ export function Table<R>({
},
}}
overflowX="auto"
className="table-root"
>
<ChakraTable.Header>
<ChakraTable.Row>
Expand All @@ -356,6 +368,7 @@ export function Table<R>({
setSortOrder={setSortOrder}
columnIndex={colIndex}
hasFixedFirstColumn={hasFixedFirstColumn}
numColumns={columnDefinitions.length}
/>
))}
</ChakraTable.Row>
Expand Down
16 changes: 12 additions & 4 deletions src/common/components/table/TableContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex, FlexProps, Stack } from '@chakra-ui/react';
import { Flex, FlexProps, Stack } from '@chakra-ui/react';

Check warning on line 1 in src/common/components/table/TableContainer.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/table/TableContainer.tsx#L1

Added line #L1 was not covered by tests
import { ReactNode } from 'react';

import { Text } from '../../../ui/Text';
Expand Down Expand Up @@ -61,10 +61,18 @@ export function TableContainer({
...rest
}: TableContainerProps) {

Check warning on line 62 in src/common/components/table/TableContainer.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/table/TableContainer.tsx#L62

Added line #L62 was not covered by tests
return (
<Stack gap={7} w="fit-content">
<Stack gap={7} w="full" className="table-container">
<Toolbar topLeft={topLeft} topRight={topRight} title={title} />
<Card h="fit-content" w="full" p={[3, 3, 4]} {...rest}>
<Box position={'relative'}>{children}</Box>
<Card
h="fit-content"
w="full"
p={[3, 3, 3, 4]}
borderColor="red"
className="table-container-card"
overflow='auto'
{...rest}
>
{children}
</Card>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function ScrollIndicatorWrapper({ children, ...rest }: BoxProps & { child
}, []);

return (
<Box position="relative">
<Box position="relative" className='scroll-indicator-positioner'>
<Box
ref={divRef}
overflowX={'auto'}
Expand Down
81 changes: 51 additions & 30 deletions src/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,49 +101,70 @@ const meta: Meta<TableStoryArgs> = {
placeholder: 'Enter height (e.g., 500px)',
},
},
decorators: [
(Story, { args }) => {
const [size, setSize] = useState({
width: args.containerWidth,
height: args.containerHeight,
});
const containerRef = useRef<HTMLDivElement>(null);
// decorators: [
// (Story, { args }) => {
// const [size, setSize] = useState({
// width: args.containerWidth,
// height: args.containerHeight,
// });
// const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const observer = new ResizeObserver(entries => {
const entry = entries[0];
if (entry) {
setSize({
width: Math.round(parseFloat(entry.contentRect.width.toString())).toString(),
height: Math.round(parseFloat(entry.contentRect.height.toString())).toString(),
});
}
});
// useEffect(() => {
// const observer = new ResizeObserver(entries => {
// const entry = entries[0];
// if (entry) {
// setSize({
// width: Math.round(parseFloat(entry.contentRect.width.toString())).toString(),
// height: Math.round(parseFloat(entry.contentRect.height.toString())).toString(),
// });
// }
// });

if (containerRef.current) {
observer.observe(containerRef.current);
}
// if (containerRef.current) {
// observer.observe(containerRef.current);
// }

return () => observer.disconnect();
}, []);
// return () => observer.disconnect();
// }, []);

// return (
// <Box
// ref={containerRef}
// w={size.width}
// h={size.height}
// bg="gray.50"
// overflow="hidden"
// border="1px solid"
// borderColor="redesignBorderPrimary"
// resize="both" // Makes this container resizable
// // style={{ maxWidth: '100%' }} // Makes this container resizable
// >
// <Stack p={10} gap={2}>
// <Text fontSize="sm" color="gray.600">
// Size: {size.width}px × {size.height}px
// </Text>
// <Story />
// </Stack>
// </Box>
// );
// },
// ],
decorators: [
(Story, { args }) => {

Check warning on line 153 in src/stories/Table.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/stories/Table.stories.tsx#L153

Added line #L153 was not covered by tests
return (
<Box
ref={containerRef}
w={size.width}
h={size.height}
w={'full'}
h={'full'}
bg="gray.50"
overflow="hidden"
border="1px solid"
borderColor="redesignBorderPrimary"
resize="both" // Makes this container resizable
// resize="both" // Makes this container resizable
// style={{ maxWidth: '100%' }} // Makes this container resizable
className='not-story-book-root'
>
<Stack p={10} gap={2}>
<Text fontSize="sm" color="gray.600">
Size: {size.width}px × {size.height}px
</Text>
<Story />
<Story w='full'/>
</Stack>
</Box>
);
Expand Down

0 comments on commit 072a607

Please sign in to comment.