Skip to content

Commit

Permalink
fix(new-hope): Edit core and storybook (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakutoc authored Apr 2, 2024
2 parents cd47ecc + 47c3916 commit 05f89c9
Show file tree
Hide file tree
Showing 36 changed files with 139 additions and 78 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { FC } from 'react';
const id = 'test-pagination';
const slots = [7, 9, 13];
const values = [1, 10, 20];
const count = 20;
const count = 2000;
const views = ['clear', 'secondary', 'primary'];

const StandardTypoStyle = createGlobalStyle(standardTypo);
Expand Down Expand Up @@ -216,12 +216,18 @@ describe('plasma-new-hope: Pagination Content', () => {
const [pageValue, setPageValue] = useState(agrs.value);
const [perPageValue, setPerPageValue] = useState(agrs.perPage);

const handleChange = useCallback(
(page: number, perPage: number) => {
const handleChangePerpage = useCallback(
(perPage: number) => {
setPerPageValue(perPage);
},
[perPageValue, setPerPageValue],
);

const handleChangePage = useCallback(
(page: number) => {
setPageValue(page);
},
[pageValue, perPageValue, setPageValue, setPerPageValue],
[pageValue, setPageValue],
);

return (
Expand All @@ -230,11 +236,12 @@ describe('plasma-new-hope: Pagination Content', () => {
{...agrs}
value={pageValue}
perPage={perPageValue}
count={count}
leftContent={
<Button
id="pagination-button-prev"
onClick={() => {
setPageValue(pageValue - 1);
handleChangePage(pageValue - 1);
}}
>
Prev
Expand All @@ -244,13 +251,14 @@ describe('plasma-new-hope: Pagination Content', () => {
<Button
id="pagination-button-next"
onClick={() => {
setPageValue(pageValue + 1);
handleChangePage(pageValue + 1);
}}
>
Next
</Button>
}
onChangeValue={handleChange}
onChangePageValue={handleChangePage}
onChangePerageValue={handleChangePerpage}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const config = {
${paginationTokens.inputWidth}: 4rem;
${paginationTokens.inputHeight}: 3.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
m: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-m-font-family);
Expand Down Expand Up @@ -212,7 +212,7 @@ export const config = {
${paginationTokens.inputWidth}: 3.5rem;
${paginationTokens.inputHeight}: 3rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
s: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-s-font-family);
Expand Down Expand Up @@ -258,7 +258,7 @@ export const config = {
${paginationTokens.inputWidth}: 3rem;
${paginationTokens.inputHeight}: 2.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
xs: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-xs-font-family);
Expand Down Expand Up @@ -304,7 +304,7 @@ export const config = {
${paginationTokens.inputWidth}: 2.5rem;
${paginationTokens.inputHeight}: 2rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
},
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Story = StoryObj<typeof Pagination>;

export const Default: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand All @@ -70,12 +70,18 @@ const PaginationContent = (agrs) => {
const [pageValue, setPageValue] = useState(agrs.value);
const [perPageValue, setPerPageValue] = useState(agrs.perPage);

const handleChange = useCallback(
(page: number, perPage: number) => {
const handleChangePerpage = useCallback(
(perPage: number) => {
setPerPageValue(perPage);
},
[perPageValue, setPerPageValue],
);

const handleChangePage = useCallback(
(page: number) => {
setPageValue(page);
},
[pageValue, perPageValue, setPageValue, setPerPageValue],
[pageValue, setPageValue],
);

return (
Expand All @@ -102,15 +108,16 @@ const PaginationContent = (agrs) => {
Next
</Button>
}
onChangeValue={handleChange}
onChangePageValue={handleChangePage}
onChangePerageValue={handleChangePerpage}
/>
</>
);
};

export const Content: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand Down
26 changes: 15 additions & 11 deletions packages/plasma-new-hope/src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const paginationRoot = (Root: RootProps<HTMLDivElement, PaginationProps>)
},
ref,
) => {
const [page, setPageValue] = useState<number>(value ?? defaultValues.value);
const [page, setPageValue] = useState<number>();
const [perPageValue, setPerPageValue] = useState(perPage);
const [pages, setPagesValue] = useState<number>(value);
const [sections, setSections] = useState<number[][] | null>(null);
Expand All @@ -75,22 +75,22 @@ export const paginationRoot = (Root: RootProps<HTMLDivElement, PaginationProps>)
};

const handlerSetPage = (newPageValue?: number) => {
newPageValue = newPageValue ?? defaultValues.value;
if (newPageValue > pages) {
newPageValue = pages;
let pageValue = newPageValue ?? defaultValues.value;
if (pageValue > pages) {
pageValue = pages;
}
if (newPageValue < 1) {
newPageValue = 1;
if (pageValue < 1) {
pageValue = 1;
}
if (disabled.includes(newPageValue)) {
if (disabled.includes(pageValue)) {
return;
}
setPageValue(newPageValue);
onChangePageValue?.(newPageValue);
setPageValue(pageValue);
onChangePageValue?.(pageValue);
};

const handlerSetPerPage = (newPerPageValue?: number) => {
setPageValue(1);
handlerSetPage(1);
setPerPageValue(newPerPageValue);
onChangePageValue?.(1);
onChangePerPageValue?.(newPerPageValue);
Expand All @@ -104,7 +104,11 @@ export const paginationRoot = (Root: RootProps<HTMLDivElement, PaginationProps>)

useEffect(() => {
handlerSetPages(perPage);
}, [perPage, handlerSetPages]);
}, [perPage, count, handlerSetPages]);

useEffect(() => {
handlerSetPage(value);
}, [value]);

useEffect(() => {
setSections(getSections(page, pages, slots));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const config = {
${paginationTokens.inputWidth}: 4rem;
${paginationTokens.inputHeight}: 3.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
m: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-m-font-family);
Expand Down Expand Up @@ -215,7 +215,7 @@ export const config = {
${paginationTokens.inputWidth}: 3.5rem;
${paginationTokens.inputHeight}: 3rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
s: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-s-font-family);
Expand Down Expand Up @@ -261,7 +261,7 @@ export const config = {
${paginationTokens.inputWidth}: 3rem;
${paginationTokens.inputHeight}: 2.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
xs: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-xs-font-family);
Expand Down Expand Up @@ -307,7 +307,7 @@ export const config = {
${paginationTokens.inputWidth}: 2.5rem;
${paginationTokens.inputHeight}: 2rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
},
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Story = StoryObj<typeof Pagination>;

export const Default: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand All @@ -71,12 +71,18 @@ const PaginationContent = (agrs) => {
const [pageValue, setPageValue] = useState(agrs.value);
const [perPageValue, setPerPageValue] = useState(agrs.perPage);

const handleChange = useCallback(
(page: number, perPage: number) => {
const handleChangePerpage = useCallback(
(perPage: number) => {
setPerPageValue(perPage);
},
[perPageValue, setPerPageValue],
);

const handleChangePage = useCallback(
(page: number) => {
setPageValue(page);
},
[pageValue, perPageValue, setPageValue, setPerPageValue],
[pageValue, setPageValue],
);

return (
Expand All @@ -103,15 +109,16 @@ const PaginationContent = (agrs) => {
Next
</Button>
}
onChangeValue={handleChange}
onChangePageValue={handleChangePage}
onChangePerageValue={handleChangePerpage}
/>
</>
);
};

export const Content: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const config = {
${paginationTokens.inputWidth}: 4rem;
${paginationTokens.inputHeight}: 3.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
m: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-m-font-family);
Expand Down Expand Up @@ -213,7 +213,7 @@ export const config = {
${paginationTokens.inputWidth}: 3.5rem;
${paginationTokens.inputHeight}: 3rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
s: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-s-font-family);
Expand Down Expand Up @@ -259,7 +259,7 @@ export const config = {
${paginationTokens.inputWidth}: 3rem;
${paginationTokens.inputHeight}: 2.5rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
xs: css`
${paginationTokens.paginationFontFamily}: var(--plasma-typo-body-xs-font-family);
Expand Down Expand Up @@ -305,7 +305,7 @@ export const config = {
${paginationTokens.inputWidth}: 2.5rem;
${paginationTokens.inputHeight}: 2rem;
${paginationTokens.inputPadding}: 0 0.625rem;
${paginationTokens.inputBorderWidth}: 0.125rem;
${paginationTokens.inputBorderWidth}: 0.0625rem;
`,
},
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Story = StoryObj<typeof Pagination>;

export const Default: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand All @@ -72,12 +72,18 @@ const PaginationContent = (agrs) => {
const [pageValue, setPageValue] = useState(agrs.value);
const [perPageValue, setPerPageValue] = useState(agrs.perPage);

const handleChange = useCallback(
(page: number, perPage: number) => {
const handleChangePerpage = useCallback(
(perPage: number) => {
setPerPageValue(perPage);
},
[perPageValue, setPerPageValue],
);

const handleChangePage = useCallback(
(page: number) => {
setPageValue(page);
},
[pageValue, perPageValue, setPageValue, setPerPageValue],
[pageValue, setPageValue],
);

return (
Expand All @@ -104,15 +110,16 @@ const PaginationContent = (agrs) => {
Next
</Button>
}
onChangeValue={handleChange}
onChangePageValue={handleChangePage}
onChangePerageValue={handleChangePerpage}
/>
</>
);
};

export const Content: Story = {
args: {
count: 20,
count: 2000,
value: 1,
slots: 9,
type: 'default',
Expand Down
Loading

0 comments on commit 05f89c9

Please sign in to comment.