Skip to content

Commit f5a2d60

Browse files
authored
feat: Add table styling (#1580)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR aims to add styling for tables, which are not currently styled: <img width="375" height="221" alt="Screenshot: Before." src="https://github.com/user-attachments/assets/2f14e5dd-a04e-465c-bca7-137e15e90fd9" /> With this PR, tables are displayed like this: <img width="464" height="249" alt="Screenshot: After." src="https://github.com/user-attachments/assets/25b88413-8c36-4a4a-ae1d-7a5cb538d178" /> Tables are also made to be scrollable (no video because Spectacle is misbehaving right now): <img width="571" height="162" alt="Screenshot: Horizontal auto-scroll on a long table." src="https://github.com/user-attachments/assets/7cd114bf-5f59-4d8b-a55b-f40a38b9fb71" /> #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] ~~Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).~~ - [ ] ~~Fully AI generated (explain what all the generated code does in moderate detail).~~ <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
2 parents 3d492c3 + 5bdea0a commit f5a2d60

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

.changeset/add_table_styling.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
# Add table styling

src/app/plugins/react-custom-html-parser.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,30 @@ export const getReactCustomHtmlParser = (
760760
);
761761
}
762762

763+
if (name === 'table') {
764+
return (
765+
<div className={css.TableContainer}>
766+
<table {...props} className={css.Table}>
767+
{renderChildren()}
768+
</table>
769+
</div>
770+
);
771+
}
772+
if (name === 'th') {
773+
return (
774+
<th {...props} className={css.Th}>
775+
{renderChildren()}
776+
</th>
777+
);
778+
}
779+
if (name === 'td') {
780+
return (
781+
<td {...props} className={css.Td}>
782+
{renderChildren()}
783+
</td>
784+
);
785+
}
786+
763787
if (name === 'code') {
764788
if (parent && 'name' in parent && parent.name === 'pre') {
765789
const codeContent = renderChildren();

src/app/styles/CustomHtml.css.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,41 @@ export const HorizontalRule = style([
300300
userSelect: 'none',
301301
},
302302
]);
303+
304+
export const TableContainer = style([
305+
DefaultReset,
306+
MarginSpaced,
307+
{
308+
overflowX: 'auto',
309+
maxWidth: '100%',
310+
},
311+
]);
312+
313+
export const Table = style([
314+
DefaultReset,
315+
{
316+
borderCollapse: 'collapse',
317+
},
318+
]);
319+
320+
export const Th = style([
321+
DefaultReset,
322+
{
323+
padding: `${config.space.S100} ${config.space.S200}`,
324+
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
325+
backgroundColor: color.SurfaceVariant.Container,
326+
color: color.SurfaceVariant.OnContainer,
327+
minWidth: toRem(100),
328+
},
329+
]);
330+
331+
export const Td = style([
332+
DefaultReset,
333+
{
334+
padding: `${config.space.S100} ${config.space.S200}`,
335+
border: `${config.borderWidth.B300} solid ${color.Surface.ContainerLine}`,
336+
backgroundColor: color.Surface.Container,
337+
color: color.Surface.OnContainer,
338+
minWidth: toRem(100),
339+
},
340+
]);

0 commit comments

Comments
 (0)