Skip to content

Commit 255a9ef

Browse files
authored
Merge pull request #318 from shairez/pr-tabs-pagination
2 parents c051c98 + ccf0383 commit 255a9ef

File tree

26 files changed

+592
-150
lines changed

26 files changed

+592
-150
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ lerna-debug.log*
5656
# misc
5757
/.sass-cache
5858
/connect.lock
59-
/coverage
59+
coverage
6060
/libpeerconnection.log
6161
testem.log
6262
/typings

.npmrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
save-exact = true
1+
save-exact = true
2+
public-hoist-pattern[]=@types*

apps/website/src/routes/docs/headless/(components)/tabs/examples.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ export const Example01 = component$(() => {
1818
</TabList>
1919
<TabPanel>
2020
<p>
21-
Maria Theresia Ahlefeldt (16 January 1755 20 December 1810) was
21+
Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was
2222
a ...
2323
</p>
2424
</TabPanel>
2525
<TabPanel>
26-
<p>Carl Joachim Andersen (29 April 1847 7 May 1909) was a ...</p>
26+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
2727
</TabPanel>
2828
<TabPanel>
2929
<p>
30-
Ida Henriette da Fonseca (July 27, 1802 July 6, 1858) was a ...
30+
Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...
3131
</p>
3232
</TabPanel>
3333
</Tabs>

apps/website/src/routes/docs/tailwind/(components)/pagination/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ export default component$(() => {
119119
boundaryCount={boundaryCount.value}
120120
/>
121121
</div>
122+
123+
<div class="flex flex-col gap-8">
124+
<Pagination
125+
pages={pages.value}
126+
page={page.value}
127+
onPaging$={(newValue: number) => {
128+
page.value = newValue;
129+
}}
130+
showFirstButton={showFirstButton.value}
131+
showLastButton={showLastButton.value}
132+
hideNextButton={hideNextButton.value}
133+
hidePrevButton={hidePrevButton.value}
134+
siblingCount={siblingCount.value}
135+
boundaryCount={boundaryCount.value}
136+
activeClass="!bg-cyan-500"
137+
defaultClass="bg-cyan-200"
138+
labels={{ prev: '⬅️', next: '➡️', first: 'START', last: 'END' }}
139+
/>
140+
</div>
122141
</div>
123142
);
124143
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.tabs-example [role='tab'] {
2+
width: 250px;
3+
background: lightgreen;
4+
}
5+
6+
.tabs-example [role='tab'].selected {
7+
background: magenta;
8+
}
9+
10+
.tabs-example [role='tablist'] {
11+
border: 1px solid;
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { component$, useStyles$ } from '@builder.io/qwik';
2+
import {
3+
Tab,
4+
TabList,
5+
TabPanel,
6+
Tabs,
7+
} from '../../../../../packages/kit-headless/src';
8+
9+
import styles from './index.css?inline';
10+
11+
export default component$(() => {
12+
useStyles$(styles);
13+
return (
14+
<div class="tabs-example">
15+
<Tabs behavior="automatic">
16+
<h3 id="tablist-1">Danish Composers</h3>
17+
<TabList>
18+
<Tab>Maria Ahlefeldt</Tab>
19+
<Tab>Carl Andersen</Tab>
20+
<Tab>Ida Henriette da Fonseca</Tab>
21+
</TabList>
22+
<TabPanel>
23+
<p>
24+
Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was a
25+
...
26+
</p>
27+
</TabPanel>
28+
<TabPanel>
29+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
30+
</TabPanel>
31+
<TabPanel>
32+
<p>
33+
Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...
34+
</p>
35+
</TabPanel>
36+
</Tabs>
37+
</div>
38+
);
39+
});

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"format:fix": "pretty-quick --staged",
1313
"prepare": "husky install",
1414
"test:headless": "nx component-test headless --watch",
15-
"story:headless": "nx build-storybook headless"
15+
"story:build:headless": "nx build-storybook headless",
16+
"story:headless": "nx storybook headless",
17+
"website": "nx serve website"
1618
},
1719
"devDependencies": {
1820
"@builder.io/qwik": "1.0.0",
@@ -25,13 +27,14 @@
2527
"@floating-ui/dom": "1.0.10",
2628
"@jscutlery/semver": "^2.30.1",
2729
"@k11r/nx-cloudflare-wrangler": "^2.0.0",
28-
"@nx/workspace": "16.0.3",
29-
"@nx/linter": "16.0.3",
3030
"@nx/cypress": "16.0.3",
31-
"@nx/storybook": "16.0.3",
3231
"@nx/eslint-plugin": "16.0.3",
32+
"@nx/linter": "16.0.3",
33+
"@nx/storybook": "16.0.3",
3334
"@nx/vite": "16.0.3",
35+
"@nx/workspace": "16.0.3",
3436
"@storybook/addon-a11y": "7.0.8",
37+
"@storybook/addon-coverage": "0.0.8",
3538
"@storybook/addon-essentials": "7.0.8",
3639
"@storybook/addon-interactions": "7.0.8",
3740
"@storybook/addon-links": "7.0.8",
@@ -44,6 +47,7 @@
4447
"@storybook/testing-library": "0.1.0",
4548
"@types/eslint": "8.37.0",
4649
"@types/node": "18.16.1",
50+
"@types/testing-library__jest-dom": "5.14.5",
4751
"@typescript-eslint/eslint-plugin": "5.59.1",
4852
"@typescript-eslint/parser": "5.59.1",
4953
"@vitest/coverage-c8": "~0.28.5",

packages/kit-headless/.storybook/tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"emitDecoratorMetadata": true
4+
"emitDecoratorMetadata": true,
5+
"types": ["node", "jest", "@testing-library/jest-dom"]
56
},
6-
77
"exclude": [
88
"../**/*.spec.ts",
99
"../**/*.test.ts",
1010
"../**/*.spec.tsx",
11-
"../**/*.test.tsx"
11+
"../**/*.test.tsx",
12+
"../cypress.config.ts"
1213
],
1314
"include": [
1415
"../src/**/*.stories.ts",

packages/kit-headless/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@
9797
"test-storybook": {
9898
"executor": "nx:run-commands",
9999
"options": {
100-
"command": "pnpm test-storybook --url http://localhost:4400",
101-
"cwd": "packages/headless"
100+
"command": "pnpm test-storybook --url http://localhost:4400 --coverage",
101+
"cwd": "packages/kit-headless"
102102
}
103103
},
104104
"component-test": {

packages/kit-headless/src/components/pagination/pagination.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import { $, component$, PropFunction, Component } from '@builder.io/qwik';
22
import { Button as HeadlessButton } from '@qwik-ui/primitives';
33

4+
/**
5+
* PAGINATION TODOs
6+
* - Get storybook testing to work
7+
*
8+
* PROPS
9+
* pageIndex: default pagination value
10+
* V activeStyles: The styles of the active page button
11+
* V normalStyles: The styles of the inactive page buttons
12+
* V customArrowTexts: { previous, next }
13+
* disabled: enable/disable paginator
14+
* color: primary | secondary
15+
* variant: outlined (show border without bg)
16+
* shape: rounded | square
17+
* size: 'sm' | 'md' | 'lg'
18+
* paginationRange (see https://mui.com/material-ui/react-pagination/#pagination-ranges)
19+
*
20+
* EVENTS
21+
* onPageChange
22+
*
23+
*/
424
export interface IPaginationProps extends IGetPaginationItemsOptions {
525
pages: number;
626
page: number;
@@ -16,8 +36,18 @@ export interface IRenderPaginationItemProps {
1636
'aria-current'?: boolean;
1737
value: TPaginationItemValue;
1838
key?: string | number;
39+
activeClass?: string;
40+
defaultClass?: string;
41+
labels?: TPaginationLabels;
1942
}
2043

44+
export type TPaginationLabels = {
45+
first?: string;
46+
last?: string;
47+
next?: string;
48+
prev?: string;
49+
};
50+
2151
export type TPaginationItemValue =
2252
| 'prev'
2353
| 'next'
@@ -55,11 +85,15 @@ export interface IGetPaginationItemsOptions {
5585
hideNextButton?: boolean;
5686
showFirstButton?: boolean;
5787
showLastButton?: boolean;
88+
activeClass?: string;
89+
defaultClass?: string;
90+
labels?: TPaginationLabels;
5891
}
5992

6093
export const getPaginationItems = (
6194
page: IGetPaginationItems['page'],
6295
count: IGetPaginationItems['count'],
96+
labels: TPaginationLabels | undefined,
6397
{
6498
boundaryCount = 1,
6599
siblingCount = 1,
@@ -159,9 +193,12 @@ export const Pagination = component$(
159193
onPaging$,
160194
page,
161195
pages,
196+
activeClass,
197+
defaultClass,
198+
labels,
162199
...rest
163200
}: IPaginationProps) => {
164-
const pagi = getPaginationItems(page, pages, rest);
201+
const pagi = getPaginationItems(page, pages, labels, rest);
165202

166203
const _onPaging$ = $((page: number) => {
167204
if (page < 1 || page > pages) return;
@@ -177,7 +214,10 @@ export const Pagination = component$(
177214
<RenderDivider key={i} />
178215
) : (
179216
<RenderItem
217+
activeClass={activeClass}
218+
defaultClass={defaultClass}
180219
key={i}
220+
labels={labels}
181221
onClick$={() =>
182222
_onPaging$(
183223
(() => {

0 commit comments

Comments
 (0)