-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7638e7
commit 6030943
Showing
9 changed files
with
163 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
apps/www/src/registry/default/plate-static-ui/table-cell-element.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
|
||
import type { StaticElementProps } from '@udecode/plate-core'; | ||
|
||
import { cn } from '@udecode/cn'; | ||
import { getTableCellBorders } from '@udecode/plate-table'; | ||
|
||
import { StaticElement } from './paragraph-element'; | ||
|
||
export function TableCellStaticElement({ | ||
children, | ||
className, | ||
element, | ||
isHeader, | ||
style, | ||
...props | ||
}: StaticElementProps & { | ||
isHeader?: boolean; | ||
}) { | ||
const borders = getTableCellBorders(element); | ||
|
||
return ( | ||
<StaticElement | ||
as={isHeader ? 'th' : 'td'} | ||
className={cn( | ||
'relative h-full overflow-visible bg-background p-0', | ||
element.background ? 'bg-[--cellBackground]' : 'bg-background', | ||
cn( | ||
isHeader && 'text-left font-normal [&_>_*]:m-0', | ||
'before:size-full', | ||
"before:absolute before:box-border before:select-none before:content-['']", | ||
borders && | ||
cn( | ||
borders.bottom?.size && `before:border-b before:border-b-border`, | ||
borders.right?.size && `before:border-r before:border-r-border`, | ||
borders.left?.size && `before:border-l before:border-l-border`, | ||
borders.top?.size && `before:border-t before:border-t-border` | ||
) | ||
), | ||
className | ||
)} | ||
style={ | ||
{ | ||
'--cellBackground': element.background, | ||
...style, | ||
} as React.CSSProperties | ||
} | ||
element={element} | ||
{...props} | ||
> | ||
<div className="relative z-20 box-border h-full px-3 py-2"> | ||
{children} | ||
</div> | ||
</StaticElement> | ||
); | ||
} | ||
|
||
export function TableCellHeaderStaticElement(props: StaticElementProps) { | ||
return <TableCellStaticElement {...props} isHeader />; | ||
} |
44 changes: 44 additions & 0 deletions
44
apps/www/src/registry/default/plate-static-ui/table-element.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
|
||
import type { StaticElementProps } from '@udecode/plate-core'; | ||
import type { TTableElement } from '@udecode/plate-table'; | ||
|
||
import { cn } from '@udecode/cn'; | ||
|
||
import { StaticElement } from './paragraph-element'; | ||
|
||
export const TableStaticElement = ({ | ||
children, | ||
className, | ||
element, | ||
...props | ||
}: StaticElementProps) => { | ||
const { colSizes } = element as TTableElement; | ||
|
||
return ( | ||
<StaticElement | ||
className={cn('overflow-x-auto', className)} | ||
element={element} | ||
{...props} | ||
> | ||
<table | ||
className={cn( | ||
'my-4 ml-px mr-0 table h-px w-[calc(100%-6px)] table-fixed border-collapse' | ||
)} | ||
> | ||
<colgroup> | ||
{colSizes?.map((width, index) => ( | ||
<col | ||
key={index} | ||
style={{ | ||
width: width || undefined, | ||
}} | ||
/> | ||
))} | ||
</colgroup> | ||
|
||
<tbody className="min-w-full">{children}</tbody> | ||
</table> | ||
</StaticElement> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
apps/www/src/registry/default/plate-static-ui/table-row-element.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import type { StaticElementProps } from '@udecode/plate-core'; | ||
|
||
import { cn } from '@udecode/cn'; | ||
|
||
import { StaticElement } from './paragraph-element'; | ||
|
||
export function TableRowStaticElement({ | ||
children, | ||
className, | ||
element, | ||
...props | ||
}: StaticElementProps) { | ||
// const { hideBorder } = element as TTableRowElement; | ||
|
||
return ( | ||
<StaticElement | ||
as="tr" | ||
className={cn('h-full', className)} | ||
element={element} | ||
{...props} | ||
> | ||
{children} | ||
</StaticElement> | ||
); | ||
} |
6 changes: 1 addition & 5 deletions
6
...s/TableCellElement/getTableCellBorders.ts → ...able/src/lib/utils/getTableCellBorders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters