Skip to content
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

feat(clerk-js,types): Add appearance keys for pagination and table head #1803

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/clean-bears-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@clerk/clerk-js': minor
'@clerk/themes': patch
'@clerk/types': minor
---

Introduces three new element appearence descriptors:

- `tableHead` let's you customize the tables head styles.
- `paginationButton` let's you customize the pagination buttons.
- `paginationRowText` let's you customize the pagination text.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ import type { MembershipRole } from '@clerk/types';
import React from 'react';

import type { LocalizationKey } from '../../customizables';
import { Col, Flex, Spinner, Table, Tbody, Td, Text, Th, Thead, Tr, useLocalizations } from '../../customizables';
import {
Col,
descriptors,
Flex,
Spinner,
Table,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
useLocalizations,
} from '../../customizables';
import { Pagination, Select, SelectButton, SelectOptionList } from '../../elements';
import type { PropsOfComponent } from '../../styledSystem';
import { roleLocalizationKey } from '../../utils';
Expand Down Expand Up @@ -54,6 +67,7 @@ export const DataTable = (props: MembersListTableProps) => {
<Tr>
{headers.map((h, index) => (
<Th
elementDescriptor={descriptors.tableHead}
key={index}
localizationKey={h}
/>
Expand Down
5 changes: 5 additions & 0 deletions packages/clerk-js/src/ui/customizables/elementDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([
'tabButton',
'tabListContainer',

'tableHead',

'paginationButton',
'paginationRowText',

'selectButton',
'selectSearchInput',
'selectButtonIcon',
Expand Down
18 changes: 7 additions & 11 deletions packages/clerk-js/src/ui/elements/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { Button, Flex, localizationKeys, Text } from '../customizables';
import { Button, descriptors, Flex, localizationKeys, Text } from '../customizables';
import type { PropsOfComponent } from '../styledSystem';
import { mqu } from '../styledSystem';
import { range } from '../utils';
Expand Down Expand Up @@ -31,6 +31,7 @@ const PageButton = (props: PropsOfComponent<typeof Button> & { isActive?: boolea
},
sx,
]}
elementDescriptor={descriptors.paginationButton}
{...rest}
/>
);
Expand All @@ -52,32 +53,27 @@ const RowInformation = (props: RowInfoProps) => {
} = props;

return (
<Text>
<Text elementDescriptor={descriptors.paginationRowText}>
<Text
as='span'
sx={t => ({
color: t.colors.$blackAlpha700,
})}
colorScheme='inherit'
localizationKey={localizationKeys('paginationRowText__displaying')}
/>{' '}
<Text
as='span'
colorScheme='inherit'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octoper I see we made some minor UI changes here, could you please add a screenshot in the PR description if needed? Even if the changes are minor, this always helps and we can use it for future reference as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's add a before and after showcasing why we need to use inherit here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I used colorScheme='inherit' here is just to have the colour to the parent element so I can use the element descriptor only theme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octoper I'm very skeptic about the result of the before/active. This is something i recently touched as well, but endup not making the change.

I don't think using the primary colour here makes sense, and the result is not that elegant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panteliselef Yeah it's not that elegant but I thought that this should match the other parts of our components that have text, because if this is not changed every other part will have the primary colour and this will be black.

sx={t => ({ fontWeight: t.fontWeights.$medium })}
>
{startingRow === endingRow && [0, 1].includes(startingRow) ? startingRow : `${startingRow} – ${endingRow}`}
</Text>{' '}
<Text
as='span'
sx={t => ({
color: t.colors.$blackAlpha700,
})}
colorScheme='inherit'
localizationKey={localizationKeys('paginationRowText__of')}
/>{' '}
<Text
as='span'
sx={t => ({
color: t.colors.$blackAlpha700,
})}
colorScheme='inherit'
>
{allRowsCount}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions packages/themes/src/createTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { Appearance, BaseTheme, DeepPartial, Elements, Theme } from '@clerk

import type { InternalTheme } from '../../clerk-js/src/ui/foundations';

type CreateClerkThemeParams = DeepPartial<Theme> & {
interface CreateClerkThemeParams extends DeepPartial<Theme> {
/**
* {@link Theme.elements}
*/
elements?: Elements | ((params: { theme: InternalTheme }) => Elements);
};
}

export const unstable_createTheme = (appearance: Appearance<CreateClerkThemeParams>): BaseTheme => {
// Placeholder method that might hande more transformations in the future
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ export type ElementsConfig = {
tabButton: WithOptions<never, never, never>;
tabListContainer: WithOptions<never, never, never>;

tableHead: WithOptions<never, never, never>;

paginationButton: WithOptions<never, never, never>;
paginationRowText: WithOptions<never, never, never>;

selectButton: WithOptions<SelectId, never, never>;
selectSearchInput: WithOptions<SelectId, never, never>;
selectButtonIcon: WithOptions<SelectId, never, never>;
Expand Down