1 | # GitLab UI
|
2 |
|
3 | GitLab UI is a UI component library that implements [Pajamas](https://design.gitlab.com/), our
|
4 | design system. GitLab UI is written in [Vue.js](https://vuejs.org) and its objectives are to:
|
5 |
|
6 | - Create reusable UI components to accelerate frontend development.
|
7 | - Create UI consistency for all components within GitLab.
|
8 |
|
9 | See <https://gitlab-org.gitlab.io/gitlab-ui/> for documentation.
|
10 |
|
11 | ## Usage
|
12 |
|
13 | To use GitLab UI in your project, add it as a dependency:
|
14 |
|
15 | ```sh
|
16 | yarn add @gitlab/ui
|
17 | ```
|
18 |
|
19 | > **Note:** Make sure to also install GitLab UI's peer dependencies. Refer to the
|
20 | > [`package.json`](./package.json) for the list of peer dependencies and their expected versions.
|
21 |
|
22 | In your main entrypoint **before** importing or using any component:
|
23 |
|
24 | ```javascript
|
25 | import setConfigs from '@gitlab/ui/dist/config'
|
26 |
|
27 | setConfigs()
|
28 | ```
|
29 |
|
30 | This will set the global configs used by GitLab UI.
|
31 |
|
32 | Import the components as desired:
|
33 |
|
34 | ```javascript
|
35 | import { GlButton } from '@gitlab/ui';
|
36 | ```
|
37 |
|
38 | GitLab UI is compatible with tree-shaking, you may enable this in your project to reduce bundle sizes.
|
39 |
|
40 | ### GitLab UI CSS
|
41 |
|
42 | GitLab UI provides component styles, a utility-class library, and SCSS utilities.
|
43 |
|
44 | - [How can I get started with GitLab UI CSS?](doc/css.md)
|
45 | - [How does GitLab UI interact with GitLab CSS?](doc/debugging-gitlab-ui-with-gitlab-css.md)
|
46 |
|
47 | ## Quick start - development
|
48 |
|
49 | **Note:** GitLab UI isn't designed to be built on Windows natively. Either
|
50 | [WSL](https://learn.microsoft.com/en-us/windows/wsl/) or
|
51 | [GitPod](https://www.gitpod.io/docs/configure/authentication/gitlab) can be used to set up a
|
52 | UNIX-like environment in which to build it.
|
53 |
|
54 | Make sure you have [Node](https://nodejs.org/en/) 16.x (LTS) and [Yarn](https://yarnpkg.com/) 1.22
|
55 | or newer.
|
56 |
|
57 | ```sh
|
58 | # Clone the project
|
59 | git clone git@gitlab.com:gitlab-org/gitlab-ui.git
|
60 |
|
61 | # Navigate to the root of the project
|
62 | cd gitlab-ui
|
63 |
|
64 | # Install all the dependencies of the project
|
65 | yarn # or yarn install
|
66 |
|
67 | # Build and launch storybook to see the components in the browser
|
68 | yarn storybook
|
69 | ```
|
70 |
|
71 | Go to <http://localhost:9001/>
|
72 |
|
73 | ## Testing
|
74 |
|
75 | ### Unit tests
|
76 |
|
77 | Components’ unit tests live in the `tests/components`. The tests are organized following the same
|
78 | directory structure used to organize components.
|
79 |
|
80 | - `yarn test:unit` runs all unit tests.
|
81 |
|
82 | - `yarn test:unit:watch` runs all unit tests in watch mode.
|
83 |
|
84 | - `yarn test:unit:debug` runs all unit tests and allow to attach a debugger to the test runner process.
|
85 |
|
86 | - `yarn jest [name_pattern]` runs spec files that match the specified name pattern.
|
87 |
|
88 | #### Examples
|
89 |
|
90 | - `yarn jest datepicker` will match all spec files with a name that contains the word _datepicker_.
|
91 |
|
92 | - `yarn jest datepicker -t "when draw event is emitted"` goes a step further and only runs the test
|
93 | with a description that matches the argument passed to the `t` flag.
|
94 |
|
95 | ### SCSS tests
|
96 |
|
97 | Even though we try to avoid writing complex SASS code to maintain CSS complexity low, we’ve
|
98 | implemented some functions that benefit from automated testing. SASS tests live in the `tests/scss`
|
99 | directory. GitLab UI uses [sass-true](https://www.oddbird.net/true/) to implement these tests, and
|
100 | jest run them.
|
101 |
|
102 | `yarn jest run_scss_tests` runs all SCSS tests.
|
103 |
|
104 | ### Visual regression tests
|
105 |
|
106 | GitLab UI uses visual snapshot tests to prevent introducing regressions with CSS and
|
107 | layout changes on components. Read more on this in the [visual testing documentation](doc/contributing/visual_testing.md).
|
108 |
|
109 | #### GitLab visual regression tests
|
110 |
|
111 | GitLab UI components are a reference implementation of the
|
112 | [Pajamas Design System components](https://design.gitlab.com/components/status). These components
|
113 | should conform with the design system specs, and they should look correct in the pajamas website and
|
114 | the GitLab product. Please see [Debugging GitLab UI issues with GitLab product CSS](doc/debugging-gitlab-ui-with-gitlab-css.md)
|
115 | for information on how to debug issues with GitLab product CSS in GitLab UI.
|
116 |
|
117 | ### End to end tests
|
118 |
|
119 | Components’ end to end tests live in the `cypress/e2e` folder. See our
|
120 | [end to end testing documentation](doc/contributing/end_to_end_test.md) for more details.
|
121 |
|
122 | `yarn run cypress open` runs Cypress locally to run end to end tests.
|
123 |
|
124 | ## Installation
|
125 |
|
126 | Install with Yarn:
|
127 |
|
128 | ```sh
|
129 | yarn add @gitlab/ui
|
130 | ```
|
131 |
|
132 | Install with npm:
|
133 |
|
134 | ```sh
|
135 | npm install @gitlab/ui
|
136 | ```
|
137 |
|
138 | ### Styles
|
139 |
|
140 | GitLab UI requires its styles to be imported to display components properly. We currently have 2
|
141 | separate stylesheets that both need to be included in your project. The main stylesheet
|
142 | (`gitlab_ui.scss`) contains component-specific styles, while the other one (`utilities.scss`)
|
143 | contains the utility classes library on which some components rely. You might find the utility
|
144 | classes useful to layout components in your own project.
|
145 |
|
146 | You have two options to include those stylesheets:
|
147 |
|
148 | - If you have a SCSS preprocessor setup, include the SCSS files in your own stylesheet:
|
149 |
|
150 | ```scss
|
151 | @import '@gitlab/ui/src/scss/gitlab_ui.scss';
|
152 | @import '@gitlab/ui/src/scss/utilities.scss';
|
153 | ```
|
154 |
|
155 | - If you don't have a SCSS preprocessor setup, you can import the compiled CSS files directly:
|
156 |
|
157 | ```css
|
158 | @import '@gitlab/ui/dist/index.css';
|
159 | @import '@gitlab/ui/dist/utility_classes.css';
|
160 | ```
|
161 |
|
162 | ## Releases
|
163 |
|
164 | See [Updating GitLab UI Packages](doc/updating-gitlab-ui-packages.md) for information on how the
|
165 | `@gitlab/ui` package is kept up to date in various projects.
|
166 |
|
167 | ## Contributing guide
|
168 |
|
169 | Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to add new components and
|
170 | contribute in general to GitLab UI.
|
171 |
|
172 | ### FAQs
|
173 |
|
174 | Any question? Have a look at our [FAQ.md](FAQ.md), you might find the answer there.
|