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

Extract the search component into @automattic/search #46424

Merged
merged 23 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"whybundled:server": "whybundled client/stats-server.json",
"composite-checkout-demo": "webpack-dev-server --config ./packages/composite-checkout/webpack.config.demo.js --mode development",
"components:storybook:start": "start-storybook -c packages/components/.storybook",
"search:storybook:start": "start-storybook -c packages/search/.storybook",
"media-library:storybook:start": "start-storybook -c packages/media-library/.storybook -h calypso.localhost -p 3001"
},
"dependencies": {
Expand Down
26 changes: 26 additions & 0 deletions packages/search/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require( 'path' );

module.exports = {
stories: [ '../src/**/*.stories.{js,jsx,ts,tsx}' ],
addons: [
'@storybook/addon-actions',
'@storybook/preset-scss',
{
name: '@storybook/preset-typescript',
options: {
tsLoaderOptions: {
transpileOnly: true,
configFile: path.resolve( __dirname, '../tsconfig.json' ),
},
tsDocgenLoaderOptions: {
tsconfigPath: path.resolve( __dirname, '../tsconfig.json' ),
},
forkTsCheckerWebpackPluginOptions: {
tsconfig: path.resolve( __dirname, '../tsconfig.json' ),
memoryLimit: 4096,
},
include: [ path.resolve( __dirname, '../src' ) ],
},
},
],
};
2 changes: 2 additions & 0 deletions packages/search/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@automattic/calypso-color-schemes';
import '@wordpress/components/build-style/style.css';
3 changes: 3 additions & 0 deletions packages/search/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Add Search component
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention that this based on the existing code in Calypso?

24 changes: 24 additions & 0 deletions packages/search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Search

A search input component.

## Installation

Install the component.

```bash
yarn add @automattic/search
```

## Internationalization

This package depends directly on `@wordpress/i18n` for translations. This means consumers must provide locale data prior to using the component.

## Development Workflow

This package is developed as part of the Calypso monorepo. Run `yarn`
in the root of the repository to get the required `devDependencies`.

### Using [Storybook](https://storybook.js.org/)

`yarn run components:storybook:start`
52 changes: 52 additions & 0 deletions packages/search/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@automattic/search",
"version": "1.0.0-alpha.3",
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we haven't released that yet, should it be 1.0.0-alpha or beta or even just 1.0.0?

"description": "Automattic Search",
"homepage": "https://github.com/Automattic/wp-calypso",
"license": "GPL-2.0-or-later",
"author": "Automattic Inc.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"sideEffects": [
"*.css",
"*.scss"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Automattic/wp-calypso.git",
"directory": "packages/search"
},
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/Automattic/wp-calypso/issues"
},
"files": [
"dist",
"src"
],
"types": "dist/types",
"dependencies": {
"@automattic/viewport": "^1.0.0",
"@babel/runtime": "^7.11.1",
"@wordpress/components": "^10.0.5",
"@wordpress/i18n": "^3.14.0",
"@wordpress/icons": "^2.4.0",
"classnames": "^2.2.6",
"lodash": "^4.17.15"
},
"peerDependencies": {
"react": "^16.8",
"react-dom": "^16.8"
},
"devDependencies": {
"@storybook/addon-actions": "^5.3.18",
"enzyme": "^3.11.0"
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't have any tests yet, it seems we can remove enzyme from the list of dependencies, no?

},
"scripts": {
"clean": "npx rimraf dist && tsc --build --clean",
"prepublish": "yarn run clean",
"prepare": "transpile && tsc && copy-assets"
Copy link
Member

@jsnajdr jsnajdr Oct 30, 2020

Choose a reason for hiding this comment

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

Hi @saramarcondes 👋 I noticed that even though the search package is written fully in TypeScript, the transpilation for the dist directories is done by Babel. The TypeScript compiler is used only to emit the type declarations.

Was this an intentional decision or is it some copy-paste accident? The compilation could be done 100% by the TypeScript compiler, with a pair of tsconfig.json and tsconfig-cjs.json config files. The @automattic/data-stores package does that, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an accident of copy and paste from the way the components package is configured. Please feel free to open a PR to fix this if you can, I’m not really familiar with how it would work without Babel...

Side note: the language picker package probably has the same problem.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I'll patch both packages in a PR 👍

}
}
1 change: 1 addition & 0 deletions packages/search/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './search';
59 changes: 59 additions & 0 deletions packages/search/src/search.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* External dependencies
*/
import React from 'react';

import Search from '.';

export default { title: 'Search', component: Search };

const BoxedSearch = ( props: any ) => (
<div style={ { position: 'relative', width: '270px', height: '50px' } }>
<Search
placeholder="Search..."
fitsContainer
onSearch={ ( search ) => console.log( 'Searched: ', search ) } // eslint-disable-line no-console
{ ...props }
/>
</div>
);

export const _default = () => {
return <BoxedSearch />;
};

export const Simple = () => {
return <BoxedSearch hideClose hideOpenIcon compact />;
};

export const Delayed = () => {
return <BoxedSearch delaySearch />;
};

export const Searching = () => {
return <BoxedSearch searching initialValue="Kiwi" />;
};

export const Disabled = () => <BoxedSearch disabled isOpen />;

export const Pinned = () => <BoxedSearch pinned />;

export const Compact = () => <BoxedSearch compact />;

export const CompactPinned = () => <BoxedSearch pinned compact fitsContainer />;

export const WithOverlayStyling = () => {
const overlayStyling = ( input: string ) => {
const tokens = input.split( /(\s+)/ );

return tokens
.filter( ( token ) => token.trim() )
.map( ( token, i ) => (
<span style={ { borderBottom: '1px solid blue', fontSize: '0.9rem' } } key={ i }>
{ token }
</span>
) );
};

return <BoxedSearch overlayStyling={ overlayStyling } />;
};
Loading