-
Notifications
You must be signed in to change notification settings - Fork 45
[WEB-4801] Add Admonition and Table MDX components #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jamiehenson
merged 3 commits into
web-4684-docs-redesign
from
web-4801-admonitions-tables
Dec 3, 2025
+224
−53
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,90 @@ | ||
| import React from 'react'; | ||
| import cn from '@ably/ui/core/utils/cn'; | ||
|
|
||
| type AdmonitionVariant = | ||
| | 'neutral' | ||
| | 'note' | ||
| | 'further-reading' | ||
| | 'important' | ||
| | 'new' | ||
| | 'warning' | ||
| | 'experimental' | ||
| | 'updated'; | ||
|
|
||
| interface AdmonitionProps extends React.HTMLAttributes<HTMLElement> { | ||
| 'data-type'?: AdmonitionVariant; | ||
| } | ||
|
|
||
| const admonitionConfig: Record< | ||
| AdmonitionVariant, | ||
| { | ||
| borderColor: string; | ||
| backgroundColor: string; | ||
| title: string; | ||
| } | ||
| > = { | ||
| neutral: { | ||
| borderColor: 'border-l-neutral-500 dark:border-l-neutral-800', | ||
| backgroundColor: 'bg-neutral-100 dark:bg-neutral-1200', | ||
| title: 'Category', | ||
| }, | ||
| note: { | ||
| borderColor: 'border-l-blue-500 dark:border-l-blue-400', | ||
| backgroundColor: 'bg-blue-100 dark:bg-blue-800', | ||
| title: 'Note', | ||
| }, | ||
| 'further-reading': { | ||
| borderColor: 'border-l-green-500 dark:border-l-green-400', | ||
| backgroundColor: 'bg-green-100 dark:bg-green-800', | ||
| title: 'Further reading', | ||
| }, | ||
| important: { | ||
| borderColor: 'border-l-orange-500 dark:border-l-orange-600', | ||
| backgroundColor: 'bg-orange-100 dark:bg-orange-1000', | ||
| title: 'Important', | ||
| }, | ||
| new: { | ||
| borderColor: 'border-l-yellow-500 dark:border-l-yellow-400', | ||
| backgroundColor: 'bg-yellow-100 dark:bg-yellow-800', | ||
| title: 'New', | ||
| }, | ||
| warning: { | ||
| borderColor: 'border-l-yellow-500 dark:border-l-yellow-400', | ||
| backgroundColor: 'bg-yellow-100 dark:bg-yellow-800', | ||
| title: 'Warning', | ||
| }, | ||
| experimental: { | ||
| borderColor: 'border-l-purple-500 dark:border-l-purple-400', | ||
| backgroundColor: 'bg-purple-100 dark:bg-purple-800', | ||
| title: 'Experimental', | ||
| }, | ||
| updated: { | ||
| borderColor: 'border-l-pink-500 dark:border-l-pink-400', | ||
| backgroundColor: 'bg-pink-100 dark:bg-pink-800', | ||
| title: 'Updated', | ||
| }, | ||
| }; | ||
|
|
||
| const Admonition: React.FC<AdmonitionProps> = ({ 'data-type': dataType = 'note', children, className, ...rest }) => { | ||
| const { borderColor, backgroundColor, title } = admonitionConfig[dataType] ?? admonitionConfig.note; | ||
|
|
||
| return ( | ||
| <aside | ||
| {...rest} | ||
| data-type={dataType} | ||
| className={cn( | ||
| 'border-l px-6 py-4 my-4 rounded-r-lg text-neutral-1000 dark:text-neutral-300', | ||
| borderColor, | ||
| backgroundColor, | ||
| className, | ||
| )} | ||
| > | ||
| <div className="text-sm leading-relaxed [&>*:first-child]:mt-0 [&>*:last-child]:mb-0 [&>*:nth-child(2)]:inline [&>*:nth-child(3)]:mt-5"> | ||
| <strong className="font-bold ui-text-p2">{title}: </strong> | ||
| {children} | ||
| </div> | ||
| </aside> | ||
| ); | ||
| }; | ||
|
|
||
| export default Admonition; |
This file contains hidden or 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,124 @@ | ||
| import React from 'react'; | ||
| import cn from '@ably/ui/core/utils/cn'; | ||
|
|
||
| // Table Root Component | ||
| interface TableRootProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableRoot: React.FC<TableRootProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <div className={cn('overflow-x-auto my-4 rounded-lg overflow-hidden', className)} {...props}> | ||
| <table className="w-full border-separate border-spacing-0 text-left text-sm">{children}</table> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Header Component | ||
| interface TableHeaderProps extends React.HTMLAttributes<HTMLTableSectionElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableHeader: React.FC<TableHeaderProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <thead className={cn('bg-neutral-100 dark:bg-neutral-1200', className)} {...props}> | ||
| {children} | ||
| </thead> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Body Component | ||
| interface TableBodyProps extends React.HTMLAttributes<HTMLTableSectionElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableBody: React.FC<TableBodyProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <tbody className={className} {...props}> | ||
| {children} | ||
| </tbody> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Row Component | ||
| interface TableRowProps extends React.HTMLAttributes<HTMLTableRowElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableRow: React.FC<TableRowProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <tr className={cn('first:border-t', className)} {...props}> | ||
| {children} | ||
| </tr> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Head Cell Component | ||
| interface TableHeadProps extends React.ThHTMLAttributes<HTMLTableCellElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableHead: React.FC<TableHeadProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <th | ||
| className={cn( | ||
| 'px-4 py-3 text-left font-bold text-neutral-1000 dark:text-neutral-300', | ||
| 'first:rounded-tl-lg last:rounded-tr-lg', | ||
| 'border-t first:border-l last:border-r border-b border-neutral-300 dark:border-neutral-1000', | ||
| className, | ||
| )} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </th> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Cell Component | ||
| interface TableCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableCell: React.FC<TableCellProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <td | ||
| className={cn( | ||
| 'px-4 py-3 font-medium text-neutral-1000 dark:text-neutral-300', | ||
| 'first:border-l last:border-r border-b border-neutral-300 dark:border-neutral-1000', | ||
| '[table>tbody:first-child_tr:first-child_&]:border-t', | ||
| '[table>tbody:first-child_tr:first-child_&]:first:rounded-tl-lg [table>tbody:first-child_tr:first-child_&]:last:rounded-tr-lg', | ||
| '[tr:last-child_&]:first:rounded-bl-lg [tr:last-child_&]:last:rounded-br-lg', | ||
| className, | ||
| )} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </td> | ||
| ); | ||
| }; | ||
|
|
||
| // Table Caption Component (optional) | ||
| interface TableCaptionProps extends React.HTMLAttributes<HTMLTableCaptionElement> { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const TableCaption: React.FC<TableCaptionProps> = ({ children, className, ...props }) => { | ||
| return ( | ||
| <caption className={cn('mt-2 text-sm text-neutral-600 dark:text-neutral-700', className)} {...props}> | ||
| {children} | ||
| </caption> | ||
| ); | ||
| }; | ||
|
|
||
| // Compound component pattern | ||
| export const Table = Object.assign(TableRoot, { | ||
| Root: TableRoot, | ||
| Header: TableHeader, | ||
| Body: TableBody, | ||
| Row: TableRow, | ||
| Head: TableHead, | ||
| Cell: TableCell, | ||
| Caption: TableCaption, | ||
| }); | ||
|
|
||
| export default Table; | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Predominantly generated by Claude but with Radix as a very close guide.