-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21951 from Yoast/367-site-kit-tables-ui
367 site kit tables UI
- Loading branch information
Showing
10 changed files
with
240 additions
and
16 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
46 changes: 46 additions & 0 deletions
46
packages/js/src/dashboard/components/most-popular-table.js
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,46 @@ | ||
import { __ } from "@wordpress/i18n"; | ||
import { TableWidget } from "./table-widget"; | ||
|
||
/** | ||
* @type {import("../index").MostPopularContent} Most popular content | ||
*/ | ||
|
||
/** | ||
* The top 5 most popular content table component. | ||
* | ||
* @param {[MostPopularContent]} Data The component props. | ||
* | ||
* @returns {JSX.Element} The element. | ||
*/ | ||
export const MostPopularTable = ( { data } ) => { | ||
return <TableWidget title={ __( "Top 5 most popular content", "wordpress-seo" ) }> | ||
<TableWidget.Head> | ||
<TableWidget.Header>{ __( "Landing page", "wordpress-seo" ) }</TableWidget.Header> | ||
<TableWidget.Header className="yst-text-end">{ __( "Clicks", "wordpress-seo" ) }</TableWidget.Header> | ||
<TableWidget.Header className="yst-text-end">{ __( "Impressions", "wordpress-seo" ) }</TableWidget.Header> | ||
<TableWidget.Header className="yst-text-end">{ __( "CTR", "wordpress-seo" ) }</TableWidget.Header> | ||
<TableWidget.Header className="yst-text-end"> | ||
{ __( "Average position", "wordpress-seo" ) } | ||
</TableWidget.Header> | ||
<TableWidget.Header className="yst-text-center"> | ||
<div className="yst-flex yst-justify-end yst-items-end"> | ||
<div className="yst-flex yst-justify-center yst-w-16"> | ||
{ __( "SEO score", "wordpress-seo" ) } | ||
</div> | ||
</div> | ||
</TableWidget.Header> | ||
</TableWidget.Head> | ||
<TableWidget.Body> | ||
{ data.map( ( { subject, clicks, impressions, ctr, averagePosition, seoScore }, index ) => ( | ||
<TableWidget.Row key={ `most-popular-content-${ index }` } index={ index }> | ||
<TableWidget.Cell className="yst-text-slate-900 yst-font-medium">{ subject }</TableWidget.Cell> | ||
<TableWidget.Cell className="yst-text-end">{ clicks }</TableWidget.Cell> | ||
<TableWidget.Cell className="yst-text-end">{ impressions }</TableWidget.Cell> | ||
<TableWidget.Cell className="yst-text-end">{ ctr }</TableWidget.Cell> | ||
<TableWidget.Cell className="yst-text-end">{ averagePosition }</TableWidget.Cell> | ||
<TableWidget.Cell><TableWidget.ScoreBullet score={ seoScore } /></TableWidget.Cell> | ||
</TableWidget.Row> | ||
) ) } | ||
</TableWidget.Body> | ||
</TableWidget>; | ||
}; |
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,80 @@ | ||
import classNames from "classnames"; | ||
import { Paper, Table, Title } from "@yoast/ui-library"; | ||
import { SCORE_META } from "../scores/score-meta"; | ||
|
||
/** | ||
* The score bullet component. | ||
* | ||
* @param {string} score The score. | ||
* @returns {JSX.Element} The element. | ||
*/ | ||
const ScoreBullet = ( { score } ) => ( | ||
<div className="yst-flex yst-justify-end yst-items-center"> | ||
<div className="yst-flex yst-justify-center yst-w-16"> | ||
<span className={ classNames( "yst-shrink-0 yst-w-3 yst-aspect-square yst-rounded-full", SCORE_META[ score ].color ) }> | ||
<span className="yst-sr-only">{ SCORE_META[ score ].label }</span> | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
|
||
/** | ||
* The table head component. | ||
* | ||
* @param {JSX.Element} children The table headers. | ||
* @returns {JSX.Element} The element. | ||
*/ | ||
const TableHead = ( { children } ) => { | ||
return <Table.Head> | ||
<Table.Row> | ||
<Table.Header className="yst-px-0">{ "" }</Table.Header> | ||
{ children } | ||
</Table.Row> | ||
</Table.Head>; | ||
}; | ||
|
||
/** | ||
* The table row component for the table widget includes numbering of first cell. | ||
* | ||
* @param {children} children The row cells. | ||
* @param {number} index The row index. | ||
* | ||
* @returns {JSX.Element} The row element. | ||
*/ | ||
const TableRow = ( { children, index } ) => { | ||
return <Table.Row> | ||
<Table.Cell className="yst-px-0 yst-text-slate-500">{ index + 1 }. </Table.Cell> | ||
{ children } | ||
</Table.Row>; | ||
}; | ||
|
||
/** | ||
* The Site Kit table component. | ||
* | ||
* @param {string} title The table title. | ||
* @param {JSX.Element} children The table rows. | ||
* | ||
* @returns {JSX.Element} The element. | ||
*/ | ||
export const TableWidget = ( { title, children } ) => { | ||
return ( | ||
<Paper className="yst-grow yst-p-8 yst-shadow-md yst-mt-6"> | ||
<Title as="h3" size="2" className="yst-text-slate-900 yst-font-medium"> | ||
{ title } | ||
</Title> | ||
<div className="yst-overflow-auto"> | ||
<Table variant="minimal"> | ||
{ children } | ||
</Table> | ||
</div> | ||
</Paper> | ||
); | ||
}; | ||
|
||
TableWidget.Head = TableHead; | ||
TableWidget.Row = TableRow; | ||
TableWidget.ScoreBullet = ScoreBullet; | ||
TableWidget.Cell = Table.Cell; | ||
TableWidget.Header = Table.Header; | ||
TableWidget.Body = Table.Body; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
The sub component `Table.Row`. | ||
The sub component `Table.Row`. The row has a variant props which can be set to `striped`. |
1 change: 1 addition & 0 deletions
1
packages/ui-library/src/elements/table/docs/table-variant-minimal.md
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 @@ | ||
The minial variant is the table without the table border. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,59 @@ | ||
@layer components { | ||
.yst-root { | ||
.yst-table-wrapper { | ||
@apply yst-rounded-lg; | ||
table { | ||
@apply yst-min-w-full; | ||
|
||
.yst-table-header { | ||
@apply yst-px-3 yst-py-4 yst-text-start yst-text-sm yst-font-semibold yst-text-slate-900; | ||
} | ||
|
||
.yst-table-cell { | ||
@apply yst-px-3 yst-py-4 yst-text-sm yst-text-slate-600; | ||
} | ||
} | ||
} | ||
|
||
.yst-table-header { | ||
@apply first:yst-rounded-ss-lg last:yst-rounded-se-lg; | ||
.yst-table--default { | ||
@apply yst-rounded-lg yst-shadow yst-ring-1 yst-ring-black yst-ring-opacity-5; | ||
|
||
table { | ||
@apply yst-divide-y yst-divide-slate-300; | ||
|
||
thead { | ||
@apply yst-bg-slate-50; | ||
|
||
.yst-table-header { | ||
@apply first:yst-rounded-ss-lg last:yst-rounded-se-lg; | ||
} | ||
} | ||
|
||
tbody { | ||
@apply yst-divide-y yst-divide-gray-200 yst-bg-white; | ||
} | ||
|
||
.yst-table-row:last-of-type .yst-table-cell { | ||
@apply first:yst-rounded-es-lg last:yst-rounded-ee-lg; | ||
} | ||
} | ||
} | ||
|
||
.yst-table-row:last-of-type .yst-table-cell { | ||
@apply first:yst-rounded-es-lg last:yst-rounded-ee-lg; | ||
.yst-table--minimal { | ||
table { | ||
@apply yst-divide-y yst-divide-slate-300; | ||
|
||
.yst-table-header { | ||
@apply yst-align-bottom yst-py-2; | ||
} | ||
|
||
.yst-table-cell { | ||
@apply yst-py-2; | ||
} | ||
|
||
tbody { | ||
@apply yst-divide-y yst-divide-gray-200 yst-bg-white; | ||
} | ||
} | ||
} | ||
} | ||
} |