Skip to content

0.11.0 #347

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

Merged
merged 8 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Currently, this repo is in Prerelease. When it is released, this project will adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
========

## 0.11.0

## Breaking Changes

- Removes options from the `Pagination` component

## 0.10.4

### Changes
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nypl/design-system-react-components",
"version": "0.10.4",
"version": "0.11.0",
"description": "Design System React Components",
"repository": {
"type": "git",
Expand Down
87 changes: 80 additions & 7 deletions src/components/Pagination/Pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,93 @@
import * as React from "react";
import { action } from "@storybook/addon-actions";
import { withDesign } from "storybook-addon-designs";
import { text } from "@storybook/addon-knobs";

import Button from "../Button/Button";
import { ButtonTypes, ButtonIconPositions } from "../Button/ButtonTypes";
import Icon from "../Icons/Icon";
import { IconNames, IconRotationTypes } from "../Icons/IconTypes";
import Label from "../Label/Label";
import Pagination from "./Pagination";
import Select from "../Select/Select";

export default {
title: "Pagination",
component: Pagination,
decorators: [withDesign],
};

export const pagination = () => (
<Pagination
paginationDropdownOptions={["1 of 4", "2 of 4", "3 of 4", "4 of 4"]}
previousPageHandler={action("goToPrevious")}
nextPageHandler={action("goToNext")}
currentValue={"1 of 4"}
onSelectChange={action("selectChange")}
onSelectBlur={action("selectBlur")}
/>
previousPage={
<Button
buttonType={ButtonTypes.Secondary}
onClick={action("Previous clicked")}
iconDecorative={true}
iconName={IconNames.arrow}
iconPosition={ButtonIconPositions.Left}
iconRotation={IconRotationTypes.rotate90}
>
{text("Previous Button Label", "Previous")}
</Button>
}
nextPage={
<Button
buttonType={ButtonTypes.Secondary}
onClick={action("Next clicked")}
iconDecorative={true}
iconName={IconNames.arrow}
iconPosition={ButtonIconPositions.Right}
iconRotation={IconRotationTypes.rotate270}
>
{text("Next Button Label", "Next")}
</Button>
}
>
<Label htmlFor="paginationSelect" id={"paginationLabel"}>
{text("Select Label", "Page ")}
</Label>
<Select
name="Pagination Select"
id={"paginationSelect"}
isRequired={false}
ariaLabel="Pagination Label"
labelId={"paginationLabel"}
onBlur={action("blur")}
onChange={action("changed")}
>
<option aria-selected={true}>
{text("Option 1 Text", "1 of 7")}
</option>
<option aria-selected={false}>
{text("Option 2 Text", "2 of 7")}
</option>
<option aria-selected={false}>
{text("Option 3 Text", "3 of 7")}
</option>
<option aria-selected={false}>
{text("Option 4 Text", "4 of 7")}
</option>
<option aria-selected={false}>
{text("Option 5 Text", "5 of 7")}
</option>
<option aria-selected={false}>
{text("Option 6 Text", "6 of 7")}
</option>
<option aria-selected={false}>
{text("Option 7 Text", "7 of 7")}
</option>
</Select>
</Pagination>
);

pagination.story = {
name: "Pagination",
parameters: {
design: {
type: "figma",
url:
"https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Master?node-id=17226%3A932",
},
},
};
86 changes: 53 additions & 33 deletions src/components/Pagination/Pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { stub } from "sinon";
import * as Enzyme from "enzyme";
import * as React from "react";

import Button from "../Button/Button";
import { ButtonTypes, ButtonIconPositions } from "../Button/ButtonTypes";
import Icon from "../Icons/Icon";
import { IconNames, IconRotationTypes } from "../Icons/IconTypes";
import Label from "../Label/Label";
import Pagination from "./Pagination";
import Select from "../Select/Select";

Expand All @@ -23,40 +28,55 @@ describe("Pagination Test", () => {
it("Renders two buttons and a Select", () => {
wrapper = Enzyme.shallow(
<Pagination
paginationDropdownOptions={[
"1 of 4",
"2 of 4",
"3 of 4",
"4 of 4",
]}
previousPageHandler={previousCallback}
nextPageHandler={nextCallback}
currentValue={"1 of 4"}
onSelectChange={changeCallback}
onSelectBlur={blurCallback}
/>
previousPage={
<Button
buttonType={ButtonTypes.Secondary}
onClick={previousCallback()}
iconDecorative={true}
iconName={IconNames.arrow}
iconPosition={ButtonIconPositions.Left}
iconRotation={IconRotationTypes.rotate90}
>
Previous
</Button>
}
nextPage={
<Button
buttonType={ButtonTypes.Secondary}
onClick={nextCallback()}
iconDecorative={true}
iconName={IconNames.arrow}
iconPosition={ButtonIconPositions.Right}
iconRotation={IconRotationTypes.rotate270}
>
Next
</Button>
}
>
<Label htmlFor="select" id={"label"}>
Page
</Label>
<Select
name="optionalLabelSelect"
id={"select"}
isRequired={false}
ariaLabel="Select Label"
labelId={"label"}
onBlur={blurCallback()}
onChange={changeCallback()}
>
<option aria-selected={true}>1 of 7</option>
<option aria-selected={false}>2 of 7</option>
<option aria-selected={false}>3 of 7</option>
<option aria-selected={false}>4 of 7</option>
<option aria-selected={false}>5 of 7</option>
<option aria-selected={false}>6 of 7</option>
<option aria-selected={false}>7 of 7</option>
</Select>
</Pagination>
);
expect(wrapper.find("Button")).to.have.lengthOf(2);
expect(wrapper.find(Select)).to.have.lengthOf(1);
});

it("Renders two buttons and a Select when there are zero pages", () => {
wrapper = Enzyme.shallow(
<Pagination
paginationDropdownOptions={[
"1 of 4",
"2 of 4",
"3 of 4",
"4 of 4",
]}
previousPageHandler={previousCallback}
nextPageHandler={nextCallback}
currentValue={"1 of 4"}
onSelectChange={changeCallback}
onSelectBlur={blurCallback}
/>
);
expect(wrapper.find("Button")).to.have.lengthOf(2);
expect(wrapper.find(Button)).to.have.lengthOf(2);
expect(wrapper.find(Select)).to.have.lengthOf(1);
expect(wrapper.find(Label)).to.have.lengthOf(1);
});
});
83 changes: 16 additions & 67 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,31 @@
import * as React from "react";
import bem from "../../utils/bem";
import Button, { ButtonOptions } from "../Button/Button";
import Label from "../Label/Label";
import Select from "../Select/Select";
import { ButtonIconPositions, ButtonTypes } from "../Button/ButtonTypes";
import { IconRotationTypes } from "../Icons/IconTypes";
export interface PaginationProps {
/** BlockName for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
blockName?: string;
/** Additional className for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
className?: string;
currentValue: string;
/** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
modifiers?: string[];
nextPageHandler: (event: React.MouseEvent) => void;
onSelectBlur: (event: React.MouseEvent) => void;
onSelectChange: (event: React.MouseEvent) => void;
paginationDropdownOptions: string[];
previousPageHandler: (event: React.MouseEvent) => void;
/** Right hand element that is the next handler, typically a button */
nextPage?: React.ReactNode;
/** Left hand element that is the previous handler, typically a button */
previousPage?: React.ReactNode;
}

export default function Pagination(props: PaginationProps) {
export default function Pagination(
props: React.PropsWithChildren<PaginationProps>
) {
const {
blockName,
children,
className,
currentValue,
modifiers,
nextPageHandler,
onSelectBlur,
onSelectChange,
paginationDropdownOptions,
previousPageHandler,
nextPage,
previousPage,
} = props;

const pagination__base_class = "pagination";
let buttonPrevOpts: ButtonOptions = {
id: "pagination-previous",
onClick: previousPageHandler,
content: <>Previous</>,
buttonType: ButtonTypes.Secondary,
iconPosition: ButtonIconPositions.Left,
iconRotation: IconRotationTypes.rotate90,
iconName: "arrow_xsmall",
iconDecorative: true,
};

let buttonNextOpts: ButtonOptions = {
id: "pagination-next",
onClick: nextPageHandler,
content: <>Next</>,
buttonType: ButtonTypes.Secondary,
iconPosition: ButtonIconPositions.Right,
iconRotation: IconRotationTypes.rotate270,
iconName: "arrow_xsmall",
iconDecorative: true,
};

let dropdownProps = {
dropdownId: "pagination-dropdown",
isRequired: false,
labelId: "pagination-select-label",
labelText: "Page",
selectedOption: currentValue,
onChange: onSelectChange,
onBlur: onSelectBlur,
};

return (
<nav
Expand All @@ -70,24 +34,9 @@ export default function Pagination(props: PaginationProps) {
className,
])}
>
<Button onClick={buttonPrevOpts.onClick} {...buttonPrevOpts}>
{buttonPrevOpts.content}
</Button>
<Label htmlFor="pagination-dropdown" id={dropdownProps.labelId}>
{dropdownProps.labelText}
</Label>
<Select
name="pagination-select"
blockName={pagination__base_class}
{...dropdownProps}
>
{paginationDropdownOptions.map((item) => (
<option aria-selected={false}>{item}</option>
))}
</Select>
<Button onClick={buttonNextOpts.onClick} {...buttonNextOpts}>
{buttonNextOpts.content}
</Button>
{previousPage}
{children}
{nextPage}
</nav>
);
}
9 changes: 3 additions & 6 deletions src/components/Pagination/_Pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

align-items: stretch;
display: flex;
justify-content: center;
width: 100%;

& > * {
> * {
&:not(:last-child) {
@include space-inline-xs;
}
Expand All @@ -18,9 +17,7 @@
align-self: center;
}

&__dropdown {
align-items: baseline;
display: flex;
justify-content: space-between;
.select {
@include space-stack-none;
}
}
1 change: 1 addition & 0 deletions src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ describe("Select", () => {
);
expect(container.find("select").instance()).to.equal(ref.current);
});
it("should throw warning when there are more than 7 options");
});
6 changes: 6 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
ariaLabelledBy = labelId + " " + helperTextId;
}

if (React.Children.count(children) > 7) {
console.warn(
"NYPL DS recommends that your <select>s have fewer than 8 options"
);
}

return (
<select
name={name}
Expand Down