Skip to content

Commit

Permalink
Merge pull request #333 from ably/table-component-ts-fixes
Browse files Browse the repository at this point in the history
[WEB-3584] add spread props to Table and Tooltip component elements, add partial icon
  • Loading branch information
jamiehenson authored Apr 9, 2024
2 parents 303968b + 210566f commit e315a31
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ably/ui",
"version": "14.0.0-dev.6d5cd62",
"version": "14.0.0-dev.99c9769",
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/core/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const coreIcons = [
"icon-gui-link-arrow",
"icon-gui-live-chat",
"icon-gui-minus",
"icon-gui-partial",
"icon-gui-plus",
"icon-gui-quote-marks-solid",
"icon-gui-refresh",
Expand Down
2 changes: 2 additions & 0 deletions src/core/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CtaCell,
Supported,
Unsupported,
Partial,
} from "./Table/TableCell";

export default {
Expand All @@ -21,4 +22,5 @@ export default {
Header: TableHeader,
Supported,
Unsupported,
Partial,
};
47 changes: 38 additions & 9 deletions src/core/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
import React, { PropsWithChildren, ReactElement, cloneElement } from "react";
import React, {
PropsWithChildren,
ReactElement,
TableHTMLAttributes,
cloneElement,
} from "react";

type TableProps = {
id?: string;
};

export const Table = ({ id, children }: PropsWithChildren<TableProps>) => (
<table id={id} className="ui-standard-container mb-4 sm:table-fixed">
export const Table = ({
id,
children,
...rest
}: PropsWithChildren<TableProps & TableHTMLAttributes<HTMLTableElement>>) => (
<table
id={id}
{...rest}
className={`ui-standard-container mb-4 sm:table-fixed ${
rest?.className ?? ""
}`}
>
{children}
</table>
);

export const TableBody = ({ children }: PropsWithChildren) => (
<tbody>{children}</tbody>
export const TableBody = ({
children,
...rest
}: PropsWithChildren<TableHTMLAttributes<HTMLTableSectionElement>>) => (
<tbody {...rest}>{children}</tbody>
);

export const TableHeader = ({ children }: PropsWithChildren) => (
<thead className="sticky bg-white z-10 top-0" key="sticky-block">
export const TableHeader = ({
children,
...rest
}: PropsWithChildren<TableHTMLAttributes<HTMLTableSectionElement>>) => (
<thead
{...rest}
className={`sticky bg-white z-10 top-0 ${rest?.className ?? ""}`}
>
{cloneElement(children as ReactElement, { isHeader: true })}
</thead>
);

export const TableRowHeader = ({ children }: PropsWithChildren) => (
export const TableRowHeader = ({
children,
...rest
}: PropsWithChildren<TableHTMLAttributes<HTMLTableRowElement>>) => (
<tr
className="-ml-24 mt-8 sm:ml-0 sm:mt-0 ui-text-overline1 !text-cool-black bg-light-grey sm:sticky z-10"
className={`-ml-24 mt-8 sm:ml-0 sm:mt-0 bg-light-grey sm:sticky z-10 ${
rest?.className ?? ""
}`}
style={{ top: "4rem" }}
>
{cloneElement(children as ReactElement, { isRowHeader: true })}
Expand Down
35 changes: 30 additions & 5 deletions src/core/Table/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ const Unsupported = () => (
/>
);

const Partial = () => (
<Icon
name="icon-gui-partial"
size="1.5rem"
additionalCSS="flex-grow-0 flex-shrink-0"
data-testid="partial-icon"
/>
);

const LabelCell = ({
children,
...rest
}: PropsWithChildren<React.TdHTMLAttributes<HTMLTableCellElement>>) => {
const classes = `
ui-text-p1 !font-bold pt-24 pb-8 border-light-grey sm:p-24 sm:relative sm:top-2 flex sm:table-cell ${
rest.className ?? ""
rest?.className ?? ""
}
`;

Expand All @@ -56,7 +65,7 @@ const TableCell = ({
? "rounded-l-none rounded-r sm:rounded-lg py-20 px-24"
: "py-6"
}
${rest.className ?? ""}
${rest?.className ?? ""}
`}
>
{children}
Expand All @@ -67,7 +76,12 @@ const HeaderCell = ({
children,
...rest
}: PropsWithChildren<React.TdHTMLAttributes<HTMLTableCellElement>>) => (
<td {...rest} className="ui-text-h3 px-24 py-24 hidden sm:table-cell">
<td
{...rest}
className={`ui-text-h3 px-24 py-24 hidden sm:table-cell ${
rest?.className ?? ""
}`}
>
{children}
</td>
);
Expand All @@ -76,9 +90,20 @@ const CtaCell = ({
children,
...rest
}: PropsWithChildren<React.TdHTMLAttributes<HTMLTableCellElement>>) => (
<td {...rest} className="pt-24 hidden sm:table-cell">
<td
{...rest}
className={`pt-24 hidden sm:table-cell ${rest?.className ?? ""}`}
>
{children}
</td>
);

export { TableCell, LabelCell, HeaderCell, CtaCell, Supported, Unsupported };
export {
TableCell,
LabelCell,
HeaderCell,
CtaCell,
Supported,
Unsupported,
Partial,
};
39 changes: 34 additions & 5 deletions src/core/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
import React, {
ButtonHTMLAttributes,
HTMLAttributes,
PropsWithChildren,
useEffect,
useRef,
useState,
} from "react";
import Icon from "./Icon";
const Tooltip = ({ children }: PropsWithChildren) => {

type TooltipProps = {
triggerProps?: ButtonHTMLAttributes<HTMLButtonElement>;
tooltipProps?: HTMLAttributes<HTMLDivElement>;
} & HTMLAttributes<HTMLDivElement>;

const Tooltip = ({
children,
triggerProps,
tooltipProps,
...rest
}: PropsWithChildren<TooltipProps>) => {
const [open, setOpen] = useState(false);
const [position, setPosition] = useState({ x: 0, y: 0 });
const offset = 8;
Expand All @@ -26,28 +44,39 @@ const Tooltip = ({ children }: PropsWithChildren) => {
}, [open]);

return (
<div className="relative inline-block align-top h-16">
<div
{...rest}
className={`relative inline-block align-top h-16 ${
rest?.className ?? ""
}`}
>
<button
onMouseEnter={() => setOpen(true)}
onMouseLeave={() => setOpen(false)}
className="ml-8 p-0 relative top-1 focus:outline-none"
type="button"
ref={reference}
aria-describedby="tooltip"
{...triggerProps}
className={`ml-8 p-0 relative top-1 focus:outline-none ${
triggerProps?.className ?? ""
}`}
>
<Icon name="icon-gui-info" size="1rem" />
</button>

{open ? (
<div
className="bg-light-grey p-12 rounded pointer-events-none absolute z-20"
role="tooltip"
ref={floating}
style={{
top: -position.y,
left: -position.x,
boxShadow: "4px 4px 15px rgba(0, 0, 0, 0.2)",
}}
{...tooltipProps}
className={`bg-light-grey p-12 rounded pointer-events-none absolute z-20 ${
tooltipProps?.className ?? ""
}`}
>
<div className="w-256">{children}</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/core/icons/icon-gui-partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e315a31

Please sign in to comment.