This repository was archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Restructure styles, improve code and docs #150
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
[](https://travis-ci.org/kubevirt/web-ui-components) | ||
[](https://coveralls.io/github/kubevirt/web-ui-components) | ||
[](https://npmjs.org/package/kubevirt-web-ui-components) | ||
[](https://opensource.org/licenses/Apache-2.0) | ||
|
||
# web-ui-components | ||
Set of reusable components identified during [kubevirt/web-ui](https://github.com/kubevirt/web-ui) development. | ||
# KubeVirt UI components | ||
|
||
Set of reusable React components identified during [kubevirt/web-ui](https://github.com/kubevirt/web-ui) development. | ||
|
||
## Playground | ||
|
||
Latest `master` version is deployed at | ||
[kubevirt.io/web-ui-components](https://kubevirt.io/web-ui-components/) ([build info](https://kubevirt.io/web-ui-components/build-info.txt)). | ||
|
||
## Documentation | ||
|
||
- [Setting up development environment](docs/DevEnvSetup.md) | ||
- [Developer guideline](docs/DevGuide.md) | ||
- [Building & publishing](docs/BuildAndPublish.md) | ||
- [Travis CI](docs/Travis.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
// https://stylelint.io/user-guide/configuration/ | ||
|
||
// This project uses the BEM (Block Element Modifier) convention for CSS classes: | ||
// http://getbem.com/naming/ | ||
// | ||
// Note that the "kubevirt" prefix is enforced to avoid potential conflicts with | ||
// the consuming application. | ||
// | ||
// For example, a "FancyForm" component could use the following class names: | ||
// - kubevirt-fancy-form | ||
// - kubevirt-fancy-form__submit-button | ||
// - kubevirt-fancy-form__submit-button--disabled | ||
|
||
const fragment = '[a-z-]+'; | ||
const prefix = 'kubevirt-'; | ||
|
||
module.exports = { | ||
extends: 'stylelint-config-standard', | ||
plugins: ['stylelint-scss'], | ||
plugins: ['stylelint-scss', 'stylelint-selector-bem-pattern'], | ||
rules: { | ||
'plugin/selector-bem-pattern': { | ||
implicitComponents: 'sass/components/**/*.scss', | ||
componentName: new RegExp(`^${fragment}$`), | ||
componentSelectors: { | ||
// validate CSS selector sequences that occur before combinators, | ||
// for example: ".foo .bar > .baz" => validate ".foo" | ||
initial: componentName => { | ||
const word = `${fragment}(?:--${fragment})*`; | ||
const element = `(?:__${word})?`; | ||
const modifier = `(?:--${word})?`; | ||
return new RegExp(`^\\.${prefix}${componentName}${element}${modifier}$`); | ||
}, | ||
// validate CSS selector sequences that occur after combinators, | ||
// for example: ".foo .bar > .baz" => validate ".bar" and ".baz" | ||
combined: () => new RegExp(`^\\.${fragment}(?:\\.${fragment})*$`), | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Building & publishing | ||
|
||
To build the project, run `yarn build`. This will regenerate the `dist` directory containing | ||
project's distributable assets. | ||
|
||
To publish the project to [npm registry](https://www.npmjs.com) and make it available for use | ||
in consuming applications, run `yarn publish`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Setting up development environment | ||
|
||
## Prerequisites | ||
|
||
Install the latest [Node.js](https://nodejs.org) Long Term Support (LTS) version. | ||
An easy way to do that is through [Node Version Manager](https://github.com/creationix/nvm), | ||
which allows you to install and switch between multiple Node.js versions: | ||
|
||
```sh | ||
nvm install 'lts/*' # install the latest LTS version | ||
nvm alias default 'lts/*' # default version to use for new shells | ||
nvm use default # switch to the default version | ||
node -v # print the current Node.js version | ||
``` | ||
|
||
Install [Yarn](https://yarnpkg.com) package manager for Node.js (latest stable version). | ||
If you'd like to install Yarn manually, download `yarn-<VERSION>.tar.gz` tarball from their | ||
[releases](https://github.com/yarnpkg/yarn/releases), extract it and add `$YARN_HOME/bin` | ||
directory to your `PATH`. | ||
|
||
## Project setup | ||
|
||
Install or update project's dependencies with Yarn: | ||
|
||
```sh | ||
yarn install | ||
``` | ||
|
||
### Cosmos | ||
|
||
Start [Cosmos](https://github.com/react-cosmos/react-cosmos) server used for testing React | ||
components an in isolated environment which simulates the consuming application: | ||
|
||
```sh | ||
yarn cosmos | ||
``` | ||
|
||
Cosmos will watch the `src` directory for changes and rebuild its playground UI accordingly. | ||
|
||
### Jest | ||
|
||
Start [Jest](https://jestjs.io) in watch mode for executing tests: | ||
|
||
```sh | ||
yarn test:watch | ||
``` | ||
|
||
Jest will watch all files ending with `.test.js` and rerun the corresponding tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Developer guideline | ||
|
||
## Component file structure | ||
|
||
``` | ||
src/components/ | ||
└── <GroupName>/ | ||
├── index.js | ||
├── <Component>.js | ||
├── <AnotherComponent>.js | ||
├── fixtures/ | ||
│ ├── <Component>.fixture.js | ||
│ └── <AnotherComponent>.fixture.js | ||
└── tests/ | ||
├── <Component>.test.js | ||
└── <AnotherComponent>.test.js | ||
``` | ||
|
||
Every component group should have an `index.js` file exporting specific components which | ||
are meant to be shipped as part of the project's npm package. | ||
|
||
Component sub-groups can be used to represent logical hierarchies, for example: | ||
|
||
``` | ||
src/components/ | ||
└── Dialog/ | ||
├── index.js | ||
└── FooDialog/ | ||
├── FooComponent.js | ||
├── fixtures/ | ||
│ └── FooComponent.fixture.js | ||
└── tests/ | ||
└── FooComponent.test.js | ||
``` | ||
|
||
For every specific component, there should be a corresponding test and a Cosmos fixture. | ||
|
||
## Stylesheet file structure | ||
|
||
``` | ||
sass/ | ||
├── components/ | ||
│ └── <GroupName> | ||
│ ├── <style-block>.scss | ||
│ └── <another-style-block>.scss | ||
└── patternfly-tweaks/ | ||
``` | ||
|
||
Styles are grouped based on React component groups, e.g. any `Form` component related styles | ||
should be placed under `sass/components/Form` directory. Styles in the `patternfly-tweaks` | ||
directory should be treated as temporary until being backported to the corresponding PF-React | ||
npm package. | ||
|
||
This project uses the [BEM (Block Element Modifier)](http://getbem.com/naming/) convention | ||
for CSS classes. Refer to [stylelint configuration](../config/stylelint.config.js) for details | ||
on project-specific BEM format. | ||
|
||
For each React component group, there may be multiple logical BEM-style selectors. Taking | ||
`src/components/Form/FormFactory` as an example, this component's render output includes | ||
PF-React's `FormGroup` with CSS class `kubevirt-form-group` added to it. In other words, | ||
different logical parts of the given component may use different CSS classes. | ||
|
||
## Cosmos | ||
|
||
Use the [Cosmos playground](https://github.com/react-cosmos/react-cosmos) to test and | ||
experiment with React components. Each component is rendered in an `iframe` along with | ||
dependant styling, allowing the component to be tested as a standalone, reusable unit. | ||
|
||
Remember to add [fixtures](https://github.com/react-cosmos/react-cosmos#fixtures) to ensure | ||
that components are properly exposed to Cosmos. Keep in mind that Cosmos is effectively the | ||
visual component interface between developers and designers: | ||
|
||
- it allows developers to test KubeVirt related UI bits | ||
- it allows designers to review the current implementation | ||
- it shields both groups from having to work with the consuming application | ||
|
||
Think of each fixture as a distinct visual test case for the given component, with `props` | ||
(and possibly other contextual information) used to exemplify the tested scenario. This is | ||
similar to testing a regular function from different angles, including known edge cases. | ||
|
||
## Jest | ||
|
||
Jest is used to run all tests. To detect test failures early, start Jest in watch mode and | ||
keep it open as you develop code. | ||
|
||
At the very least, every React component should have an accompanying | ||
[snapshot test](https://jestjs.io/docs/en/snapshot-testing) to guard against regressions | ||
in its render output. | ||
|
||
Avoid big `it` blocks. Prefer small, focused test cases which are easy to read and refactor. | ||
|
||
## Validations | ||
|
||
This project uses a simple validation mechanism driven by `tools/runValidations.js` script. | ||
New validations can be added to `tools/validations` directory as CommonJS modules exporting | ||
a function, for example: | ||
|
||
```js | ||
module.exports = () => { | ||
return true; // validation success | ||
}; | ||
``` | ||
|
||
## How to | ||
|
||
### Lint, validate and test the project in one go? | ||
|
||
```sh | ||
yarn test | ||
``` | ||
|
||
### Run specific tests? | ||
|
||
```sh | ||
yarn jest -t 'TestNameRegexp' | ||
``` | ||
|
||
### Update snapshots for specific tests? | ||
|
||
```sh | ||
yarn jest -t 'TestNameRegexp' -u | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Travis CI | ||
|
||
This project hooks into the [Travis job lifecycle](https://docs.travis-ci.com/user/job-lifecycle) | ||
through following scripts: | ||
|
||
- `before_script`: runs `tools/travis/beforeScript.js` | ||
- `after_success`: runs `tools/travis/afterSuccess.js` | ||
|
||
Refer to [Travis configuration](../.travis.yml) for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
@import './components/HelloWorld'; | ||
@import './components/ButtonWithIcon'; | ||
@import './components/CreateVmWizard'; | ||
@import './components/Dropdown'; | ||
@import './components/EditableDraggableTable'; | ||
@import './components/FormFactory'; | ||
@import './components/NewVmWizard'; | ||
@import './components/ResultTab'; | ||
@import './components/NetworksTab'; | ||
@import './components/StorageTab'; | ||
@import './components/VmStatus'; | ||
@import './components/VmConsoles'; | ||
@import './components/TemplateSource'; | ||
@import './components/CreateDiskRow'; | ||
@import './components/VmDetails'; | ||
/* | ||
KubeVirt UI component styles. Refer to stylelint configuration for details | ||
on project-specific BEM (Block Element Modifier) format for CSS classes. | ||
*/ | ||
|
||
@import './components/CreateDiskRow/create-disk-row'; | ||
@import './components/Form/dropdown'; | ||
@import './components/Form/form-group'; | ||
@import './components/Form/list-form-factory'; | ||
@import './components/Table/editable-table-actions'; | ||
@import './components/Table/editable-table'; | ||
@import './components/TemplateSource/template-source'; | ||
@import './components/VmConsoles/vm-consoles'; | ||
@import './components/VmDetails/vm-details'; | ||
@import './components/VmStatus/vm-status'; | ||
@import './components/Wizard/create-vm-wizard'; | ||
@import './components/Wizard/wizard'; | ||
|
||
/* | ||
TODO: these styles should be backported to the corresponding PF-React package | ||
*/ | ||
@import './patternfly-tweaks/vnc-console'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.kubevirt-create-disk-row__action-buttons { | ||
width: 27px; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
top: 5px; | ||
} | ||
|
||
.kubevirt-dropdownGroup .dropdown-menu { | ||
.kubevirt-dropdown + .dropdown-menu { | ||
width: 100%; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.kubevirt-form-group .dropdown > .dropdown-menu { | ||
display: none; | ||
z-index: 1001; | ||
} | ||
|
||
.kubevirt-form-group .dropdown.open > .dropdown-menu { | ||
display: block; | ||
} | ||
|
||
.kubevirt-form-group--no-bottom { | ||
margin-bottom: 2px; | ||
} | ||
|
||
.kubevirt-form-group--help { | ||
margin-bottom: 0; | ||
} | ||
|
||
.kubevirt-form-group--no-help { | ||
margin-bottom: 23px; | ||
} | ||
|
||
.kubevirt-form-group__field-help .popover { | ||
max-width: 400px; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was
.createDiskRow__actionButtons button
previously so the new style should look like.kubevirt-create-disk-row__action-buttons button
or.kubevirt-create-disk-row__action-buttons .btn
(i think the latter is better). I need to target nested buttons inside.kubevirt-create-disk-row__action-buttons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, I've missed that.
Since we need to target specific buttons, we can use
.kubevirt-create-disk-row__action-button
(singular) class name on<Button>
components, if you agree.We don't have to declare
.kubevirt-create-disk-row__action-buttons
(plural) if we don't need to style the enclosing<div>
(button panel/container).Nested CSS selectors should only be used when we don't have full control over the logical component's parts. In this case, we can simply use
.kubevirt-create-disk-row__action-button
, since PF-React's<Button>
allows us to specify CSS class name..block tag
selectors should be avoided if possible. CSS rules shouldn't be tied to HTML tags..block .nested-part
selectors are possible, but unnecessary in this case.