Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
368604f
feat: Port Pipeline and Stage component from MongoDB Charts to LeafyG…
matt-d-rat Oct 29, 2019
234f9c4
chore: Upgrade jest-dom to latest version (@testing-library/jest-dom)…
matt-d-rat Nov 8, 2019
f7c26ad
chore: Add typings for external react-merge-refs dependency
matt-d-rat Nov 8, 2019
05110b6
chore: Move IntersectionObserver mock to pipeline src
matt-d-rat Nov 8, 2019
e50c168
fix: Missing title prop from MenuItemProps typescript interface
matt-d-rat Nov 8, 2019
fcba14e
Revert "fix: Missing title prop from MenuItemProps typescript interface"
matt-d-rat Nov 12, 2019
6665587
fix: Remove deprecated title prop from MenuItem
matt-d-rat Nov 12, 2019
8d0d945
chore: Pipeline package version set to v0.9.0. Updated all dependenci…
matt-d-rat Nov 12, 2019
014c105
chore: Fix incorrect references in JSDoc
matt-d-rat Nov 12, 2019
103c66c
chore: PR feedback (deconstruct style, export interface, remove named…
matt-d-rat Nov 21, 2019
6f05937
chore: PR feedback (prefer flex-grow, flex-shrink, flex-basis over fl…
matt-d-rat Nov 21, 2019
0756bbb
chore: PR feedback (Add data attributes using createDataProp)
matt-d-rat Nov 21, 2019
01da661
chore: PR feedback (default util function exports. Remove named exports)
matt-d-rat Nov 21, 2019
8730911
chore: PR feedback (prefer native Array.flatMap instead of lodash met…
matt-d-rat Nov 21, 2019
c1dec5f
chore: PR feedback (update getPupelineCounterTooltip util. Prefer nat…
matt-d-rat Nov 21, 2019
aac05ee
chore: PR feedback (rename isStageElement.spec.ts -> packages/pipelin…
matt-d-rat Nov 21, 2019
2777e6f
chore: PR feedback (set default values in function params for Stage /…
matt-d-rat Nov 21, 2019
1cc74e6
fix: getPipelineCounterTooltip to use lodash flatMap, as native flatM…
matt-d-rat Nov 21, 2019
414ed72
fix: Failing test in Logo due to upgrade of jest-dom to testing-libra…
matt-d-rat Nov 21, 2019
c1660c3
fix: Trigger observer side effects when Pipeline childList updates.
matt-d-rat Nov 21, 2019
6d0ee4f
chore: PR feedback (remove React defaultProps in favour of destructur…
matt-d-rat Nov 22, 2019
a3b2df5
chore: Resolve yarn.lock conflict following rebase
matt-d-rat Dec 3, 2019
4f4a0e9
chore: PR feedback - provide one way of importing (remove default exp…
matt-d-rat Dec 3, 2019
b413193
chore: PR feedback - fix spelling mistakes. Add .vscode directory to …
matt-d-rat Dec 3, 2019
4295dad
chore: PR feedback - prefer ? syntax for optional types
matt-d-rat Dec 3, 2019
d2a3cfc
chore: PR feedback - update lodash import to use subpackage for bette…
matt-d-rat Dec 3, 2019
d15f443
chore: PR feedback - don't export StateForStyles interface. Unnecessary
matt-d-rat Dec 3, 2019
beadd1d
chore: PR feedback - don't export Props interface. Unnecessary
matt-d-rat Dec 3, 2019
c863adc
chore: PR feedback - rename _children to a more semantic name: childr…
matt-d-rat Dec 3, 2019
416a209
chore: PR feedback - improve the description of the isElementOverflow…
matt-d-rat Dec 4, 2019
b178135
chore: PR feedback - move IntersectionObserver mock to root mocks fol…
matt-d-rat Dec 4, 2019
cccf6d1
fix: Remove --parallel flag from yarn build command. CircleCI exhaust…
matt-d-rat Dec 4, 2019
b054431
Revert "chore: PR feedback - move IntersectionObserver mock to root m…
matt-d-rat Dec 4, 2019
0cf5485
chore: PR feedback. Remove .vscode .gitignore entry (prefer adding to…
matt-d-rat Dec 16, 2019
b6c1bc0
chore: PR feedback - Remove Variant feature from Pipeline and associa…
matt-d-rat Dec 16, 2019
c743f4c
chore: Generate change logs
matt-d-rat Dec 18, 2019
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 .changeset/chilled-pants-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@leafygreen-ui/pipeline': major
'@leafygreen-ui/menu': patch
---

Initial release of @leafygreen-ui/pipeline component. Removed deprecated title prop from the @leafygreen-ui/menu component propTypes.
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ module.exports = {
'.svg': '<rootDir>/__mocks__/svgTransformer.js',
},

// Ignore transforming node_modules except for:
// 1. `react-children-utilities`
transformIgnorePatterns: ['/node_modules/(?!(react-children-utilities)/)'],

setupFiles: ['<rootDir>/scripts/jestSetup.js'],
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"start": "start-storybook -p 9001 -c storybook -s ./storybook/static",
"build": "lerna run --parallel build -- --env production",
"build": "lerna run build -- --env production",
"build:storybook": "build-storybook -c storybook -o ./storybook/public -s ./storybook/static",
"clean": "rimraf packages/*/{dist,node_modules} node_modules",
"create-package": "node ./scripts/package-builder.js",
Expand Down Expand Up @@ -66,6 +66,7 @@
"@storybook/theming": "^5.2.5",
"@svgr/babel-plugin-replace-jsx-attribute-value": "^4.2.0",
"@svgr/webpack": "^4.3.3",
"@testing-library/jest-dom": "^4.2.3",
"@testing-library/react": "^8.0.1",
"@testing-library/react-hooks": "^2.0.1",
"@types/facepaint": "^1.2.1",
Expand Down Expand Up @@ -99,7 +100,6 @@
"gh-pages": "^2.1.1",
"husky": "^3.0.9",
"jest": "23.6.0",
"jest-dom": "^3.2.2",
"jest-junit": "^6.3.0",
"lerna": "3.18.3",
"polished": "^3.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/logo/src/Logo.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import 'jest-dom/extend-expect';
import '@testing-library/jest-dom/extend-expect';
import { Logo, LogoMark } from '.';

afterAll(cleanup);
Expand Down
2 changes: 1 addition & 1 deletion packages/menu/src/Menu.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import 'jest-dom/extend-expect';
import '@testing-library/jest-dom/extend-expect';
import { render, fireEvent, cleanup } from '@testing-library/react';
import { Menu, MenuSeparator, MenuItem } from './index';

Expand Down
1 change: 0 additions & 1 deletion packages/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ MenuItem.propTypes = {
href: PropTypes.string,
onClick: PropTypes.func,
className: PropTypes.string,
title: PropTypes.string,
description: PropTypes.string,
disabled: PropTypes.bool,
active: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/modal/src/Modal.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import 'jest-dom/extend-expect';
import '@testing-library/jest-dom/extend-expect';
import Modal from './Modal';

afterAll(cleanup);
Expand Down
2 changes: 1 addition & 1 deletion packages/mongo-menu/src/MongoMenu.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import 'jest-dom/extend-expect';
import '@testing-library/jest-dom/extend-expect';
import { render, fireEvent, cleanup } from '@testing-library/react';
import MongoMenu from '.';

Expand Down
91 changes: 91 additions & 0 deletions packages/pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Pipeline

![npm (scoped)](https://img.shields.io/npm/v/@leafygreen-ui/pipeline.svg)

## Usage

```shell
npm install @leafygreen-ui/pipeline
```

### Example

```js
<Pipeline size="xsmall" className="my-pipeline">
<Stage>$match</Stage>
<Stage>$addFields</Stage>
<Stage>$limit</Stage>
</Pipeline>
```

### Output HTML

```html
<div data-leafygreen-ui="pipeline" class="leafygreen-ui-1hmty9x my-pipeline">
<ol data-leafygreen-ui="pipeline-stages" class="leafygreen-ui-7mx6fb">
<li
data-leafygreen-ui="pipeline-stage"
class="leafygreen-ui-11gdvjk"
data-stage-visible="true"
>
$match
<div
data-leafygreen-ui="pipeline-stage-chevron"
class="leafygreen-ui-pglvth"
/>
</li>
<li
data-leafygreen-ui="pipeline-stage"
class="leafygreen-ui-11gdvjk leafygreen-ui-pipeline-stage--last-visible"
data-stage-visible="true"
>
$addFields
<div
data-leafygreen-ui="pipeline-stage-chevron"
class="leafygreen-ui-pglvth"
/>
</li>
<li
data-leafygreen-ui="pipeline-stage"
class="leafygreen-ui-11gdvjk"
data-stage-visible="false"
>
$limit
<div
data-leafygreen-ui="pipeline-stage-chevron"
class="leafygreen-ui-pglvth"
/>
</li>
</ol>
<div data-leafygreen-ui="pipeline-counter" class="leafygreen-ui-1iicq0p">
<div
data-leafygreen-ui="pipeline-counter-chevron"
class="leafygreen-ui-18yu2oo"
/>
</div>
</div>
```

## Properties

### Pipeline

| Prop | Type | Description | Default |
| ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `className` | `String` | Adds a className to the class attribute. | `''` |
| `children` | `Node` | The content that will render inside of the component. If any nodes other than `Stage` components are passed in as children, the `Pipeline` component will automatically wrap them with `Stage` components. | `undefined` |
| `size` | `String` | Sets the size variant of the Pipeline. Valid sizes are: `'xsmall'`, `'small'`, `'normal'`, and `'large'` | `'xsmall'` |

_All other props will be spread onto the root element._

### Stage

| Prop | Type | Description | Default |
| ------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `className` | `String` | Adds a className to the class attribute. | `''` |
| `children` | `Node` | The content that will render inside of the component. | `undefined` |
| `intersectionNode` | `Element` | The DOM element to observe intersections with. When used with the `Pipeline` component, this prop is automatically set to the element rendered by the `Pipeline`. | `window` |
| `threshold` | `Number` | Either a single number or an array of numbers which indicate at what percentage of the target's visibility, the observer's callback should be executed. | `0.8` |
| `size` | `String` | Sets the size variant of the Pipeline. Valid sizes are: `'xsmall'`, `'small'`, `'normal'`, and `'large'` | `'xsmall'` |

_All other props will be spread onto the root element. The Pipeline component will also decorate the child Stage components with the `size` prop that it is supplied with._
26 changes: 26 additions & 0 deletions packages/pipeline/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@leafygreen-ui/pipeline",
"version": "0.9.0",
"description": "LeafyGreen UI Kit Pipeline",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "../../node_modules/.bin/webpack --config ../../webpack.config.js"
},
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@leafygreen-ui/emotion": "^1.0.6",
"@leafygreen-ui/hooks": "^1.1.0",
"@leafygreen-ui/lib": "^3.2.0",
"@leafygreen-ui/palette": "^1.1.0",
"@leafygreen-ui/tooltip": "^2.0.0",
"lodash": "^4.17.15",
"react-children-utilities": "^2.0.0",
"react-intersection-observer": "^8.25.1",
"react-merge-refs": "^1.0.0"
},
"gitHead": "dd71a2d404218ccec2e657df9c0263dc1c15b9e0"
}
29 changes: 29 additions & 0 deletions packages/pipeline/src/Counter.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { typeIs } from '@leafygreen-ui/lib';
import Counter from './Counter';
import { Size } from './styles';

const className = 'test-counter-class';

function renderCounter(props = {}) {
const utils = render(<Counter {...props} size={Size.XSmall} />);

if (!typeIs.element(utils.container.firstChild)) {
throw new Error('Counter element not found');
}

return {
...utils,
element: utils.container.firstChild,
};
}

afterAll(cleanup);

describe('packages/pipeline/Counter', () => {
test(`renders "${className}" in the stage's classList`, () => {
const { element } = renderCounter({ className });
expect(element.classList.contains(className)).toBe(true);
});
});
141 changes: 141 additions & 0 deletions packages/pipeline/src/Counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import React, { forwardRef, ReactElement, ReactNode, Ref } from 'react';
import PropTypes from 'prop-types';
import { css, cx } from '@leafygreen-ui/emotion';

import {
getRootStyle,
getChildStyle,
getChevronStyle,
Size,
layout,
colors,
counterAttr,
counterChevronAttr,
} from './styles';

interface StateForStyles {
size?: Size;
}

interface CounterProps {
/**
* Content that will appear inside of the Counter component.
*/
children?: ReactNode;

/**
* Classname applied to Counter content container.
**/
className?: string;

/**
* Alter the rendered size of the component. Inherited from the parent Pipeline component.
*/
size: Size;
}

const getBaseStyle = ({ size = Size.XSmall }: StateForStyles): string => {
const { chevron, fontSize, fontWeight, gutter, height, lineHeight } = layout[
size
];

const { color, secondary } = colors;
const outerSize = height / 2;
const offset = outerSize + chevron.size * 2;

return cx(
getRootStyle({ size }),
getChildStyle({ size }),
css`
background-color: ${secondary.backgroundColor};
color: ${color};
padding: ${gutter.vertical}px ${gutter.horizontal}px;
margin-right: ${offset}px;
font-size: ${fontSize}px;
font-weight: ${fontWeight};
line-height: ${lineHeight};
flex: 1 1 auto;
white-space: nowrap;
z-index: 2;

&::before {
white-space: nowrap;
content: '+' counter(hiddenCount);
}
`,
);
};

const getCounterChevronStyle = ({
size = Size.XSmall,
}: StateForStyles): string => {
const { chevron, height } = layout[size];
const { secondary } = colors;
const outerSize = height / 2;

return cx(
getChevronStyle({ size }),
css`
&::before {
background-color: ${secondary.backgroundColor};
box-shadow: 0 0 0 ${chevron.size}px transparent,
0 0 0 ${outerSize}px transparent;
}
`,
);
};

const getStatefulStyles = (state: StateForStyles) => ({
base: getBaseStyle(state),
chevron: getCounterChevronStyle(state),
});

/**
* # Counter
*
* React Component to render the counter for the number of hidden stages in the Pipeline component.
*
* ```
* <Counter />
* ```
* @param props.className Classname applied to Counter content container.
*/
const Counter = forwardRef(
(
{ className = '', children, size, ...rest }: CounterProps,
ref: Ref<HTMLDivElement>,
): ReactElement => {
const { base: baseStyle, chevron: chevronStyle } = getStatefulStyles({
size,
});

return (
<div
{...rest}
{...counterAttr.prop}
data-testid="pipeline-counter"
className={cx(baseStyle, className)}
ref={ref}
>
{/* Children will be the tooltip provided by the Pipeline component */}
{children}

<div
{...counterChevronAttr.prop}
data-testid="pipeline-counter-chevron"
className={chevronStyle}
/>
</div>
);
},
);

Counter.displayName = 'Counter';

Counter.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
size: PropTypes.oneOf(Object.values(Size)).isRequired,
};

export default Counter;
Loading