diff --git a/docs/pages/css/tools/atom-packages.md b/docs/pages/css/tools/atom-packages.md new file mode 100644 index 00000000..9806dd00 --- /dev/null +++ b/docs/pages/css/tools/atom-packages.md @@ -0,0 +1,55 @@ +--- +title: Atom packages +doc_type: css +category: tools +--- + +[Atom editor](https://atom.io/) is a _"A hackable text editor for the 21st Century"_ built by GitHub. If you use it as your editor of choice, the design systems team has a list of packages that we find useful for CSS development. + +We keep a list of suggested packages in our [atom-packages repository](https://github.com/primer/atom-packages). To install all packages, run this command in your terminal. + +```sh +apm install $(curl -L https://raw.githubusercontent.com/primer/atom-packages/master/packages) +``` + +{:toc} + +## Autocomplete Primer + +The [Autocomplete Primer package](https://atom.io/packages/autocomplete-primer) is a custom [Primer](https://github.com/primer) package that autocompletes class names for [utilities](https://github.com/primer/primer/tree/master/modules/primer-utilities) and rails helper tags for [octicons](https://github.com/primer/octicons/tree/master/lib/octicons_helper). + +Install [autocomplete-primer](https://atom.io/packages/autocomplete-primer) using Atom's package manager or enter this into your terminal: + +```sh +apm install autocomplete-primer +``` + +## Color picker + +[Color picker](https://atom.io/packages/color-picker) adds a color picking overlay with sliders and color wheels. + +Install [color-picker](https://atom.io/packages/color-picker) using Atom's package manager or enter this into your terminal: + +```sh +apm install color-picker +``` + +## Pigments + +[Pigments](https://atom.io/packages/pigments) adds corresponding backgrounds to CSS color values in the editor for higher visibility. It also scans the source files for color variables and displays the true value. + +Install [pigments](https://atom.io/packages/pigments) using Atom's package manager or enter this into your terminal: + +```sh +apm install pigments +``` + +## Stylelint linter + +We use [Stylelint](./linting/) for linting our CSS, which is an extension to the [Atom linter](https://atom.io/packages/linter) package. To prevent linting errors during the build we recommend you install [linter-stylelint](https://atom.io/packages/linter-stylelint) which will alert you of any errors locally while you work. + +Install [linter-stylelint](https://atom.io/packages/linter-stylelint) using Atom's package manager or enter this into your terminal: + +```sh +apm install linter linter-stylelint +``` diff --git a/docs/pages/css/tools/docset.md b/docs/pages/css/tools/docset.md new file mode 100644 index 00000000..30a0cd18 --- /dev/null +++ b/docs/pages/css/tools/docset.md @@ -0,0 +1,19 @@ +--- +title: Docset +doc_type: css +category: tools +--- + +We use and ❤️ [Kapeli's Dash app][dash] for browsing API documentation. Dash comes with 150+ offline documentation sets, but doesn't have our style guide. + +So we've generated a [GitHub Style Guide docset][dash-feed] that gives you access to this site offline. + +## Installation + +1. First you'll need to make sure you have [Dash app][dash] installed. +2. Once installed, open the app, and click this [install docset link][dash-feed]. +3. After the docset has been added to your list, click "download". +![](https://user-images.githubusercontent.com/54012/32087284-a87ed8f4-ba8f-11e7-9d84-c61913336491.png) + +[dash]: https://kapeli.com/dash +[dash-feed]: dash-feed://https%3A%2F%2Fstyleguide.github.com%2Ffeeds%2FGitHub%20Style%20Guide.xml diff --git a/docs/pages/css/tools/index.md b/docs/pages/css/tools/index.md new file mode 100644 index 00000000..b03577c6 --- /dev/null +++ b/docs/pages/css/tools/index.md @@ -0,0 +1,9 @@ +--- +title: Tools +doc_type: css +category: tools +sidebar: {root: true} +--- + +Design and development tools for working with the GitHub CSS toolkit. + diff --git a/docs/pages/css/tools/linting.md b/docs/pages/css/tools/linting.md new file mode 100644 index 00000000..9909a9e5 --- /dev/null +++ b/docs/pages/css/tools/linting.md @@ -0,0 +1,103 @@ +--- +title: Linting +doc_type: css +category: tools +--- + +We use linters to enforce [coding principles and standards](../principles/). On every pull request we run the linters on the code to make sure any changes meet our standards. When a commit contains code that doesn't meet the standards, the build fails which blocks merging into master and deploying to production. + +For teams working on `github/github` this configuration is all setup for you. While we do recommend you also [setup a plugin](#plugins) in your editor, this is not required. + +For everyone else we encourage you to adopt all or some of these tools in your workflow. + +{:toc} + +## CSS + +We use [stylelint](http://stylelint.io/) to lint our CSS. If you are working on `github/github` you don't need to do any setup because stylelint comes bundled within the repository. If you are working on other properties, you may need to setup stylelint. You can install stylelint via npm: + +``` +npm install -g stylelint +``` + +Whether you work on `github/github` or not, it's useful to see lint errors locally. The easiest way to lint your code is to install a [plugin](#plugins) in your workflow. If you prefer to run stylelint manually, pass it a glob pattern of the files you want to lint. If you work on `github/github`, you can run stylelint from the command line: + +``` +bin/stylelint "app/assets/stylesheets/**/*.scss" --syntax scss +``` + +For more advanced usage, we recommend reading the [stylelint user guide](http://stylelint.io/user-guide/) and checking out our [primer stylelint configuration](https://github.com/primer/primer/tree/master/tools/stylelint-config-primer). + +### Configuration + +Stylelint is [configured by a JSON file](http://stylelint.io/user-guide/configuration/) that specifies which linter rules we enforce. If you are working on `github/github`, you don't need to do any setup because the configuration is included within the repository bundle. + +We have extracted out our configuration file into a separate repository [primer/stylelint-config-primer](https://github.com/primer/primer/tree/master/tools/stylelint-config-primer). This gives us a central source where we can keep the configuration up-to-date and distribute easily across all our projects. + +To [use the configuration](https://github.com/primer/primer/tree/master/tools/stylelint-config-primer#usage) in your project, install the config `npm install --save stylelint-config-primer` via npm, and extend the config in your `.stylelintrc` file. Put the file in the root directory of your project. + +```json +{ + "extends": "stylelint-config-primer" +} +``` + +A list of all the specific rules we have enabled are documented in [the repository README](https://github.com/primer/primer/tree/master/tools/stylelint-config-primer#documentation). + +### Disabling + +We use linters to help ensure our CSS is written according to our principles. On occasion it's necessary to break those principles and disable a linter. This is usually because of one of the following scenarios: +- There is no other way to achieve the desired style due to other code limitations, such as the way the views are rendered or the way the content is output (such as rendered markdown). +- There is no other way to achieve the desired style due to conflicts with existing styles that would require considerable effort to fix. +- Breaking a lint rule offers an improvement to code readability and/or maintainability (this is often the case when writing components and supporting SCSS, such as mixins and functions). + +To disable a linter, place a `// stylelint-disable` comment around the specific block of CSS that you need to override. For example: + +```scss +// When a branch name is a link +// stylelint-disable selector-no-qualifying-type +a.branch-name { color: $brand-blue; } +// stylelint-enable selector-no-qualifying-type +``` + +1. You'll need to specify a reason for disabling the lint. +2. Say what lint you're disabling, this example has `selector-no-qualifying-type`. +3. Make sure to `disable` then `enable` the lint again after your code block. This is so the lint is in effect for only that specific rule block. + +When you disable a linter on GitHub, [Sentinel](https://github.com/github/sentinel) will post a comment on your pull request notifying the Design Systems team of this override. This is because disabled lints act as a signal that there may be problems with our style guide or with the CSS being added. + +While linters shouldn't be disabled without consideration, essentially they act as a guide to how we write CSS rather than steadfast rules. For more info on disabling configuration, visit the [stylelint docs](http://stylelint.io/user-guide/configuration/#turning-rules-off-from-within-your-css). + +### Plugins + +Our linter runs on every commit, but finding you have a lint error after a push can be frustrating and waste time. To avoid this, a [collection of editor plugins](http://stylelint.io/user-guide/complementary-tools/) are available to help you lint while you code.. + +The Design Systems team recommends using [Atom](https://atom.io/) with the [linter-stylelint](https://github.com/AtomLinter/linter-stylelint) package installed. + +![image](https://cloud.githubusercontent.com/assets/54012/21456489/6a10b370-c8f6-11e6-9199-bb3709e79794.png) + +We also have a [list of Atom plugins](../tools/atom-plugins/) that we find useful for development. + +## HTML + +A custom Rails test called `styles_match_markup_test.rb` runs for our `.html.erb` files and checks for unused selectors. The test collects a list of all the class names used in our markup, JavaScript and documentation, then compares that with a list of all our class names in our `.scss` files. + +This test isn't smart enough to know about CSS inheritance, but will help you catch any dead CSS in your markup or styles. Run the test locally with this command. + +``` +bin/testrb test/fast/linting/styles_match_markup_test.rb +``` + +Sometimes you will have generated class names that the test misses. Adding these class names to the regular expression enabled `selectors_match_markup_whitelist.yml` file will quiet the tests. + +## Files + +We enforce `.scss` file naming to be lowercase, only use `-` hyphens and no leading `_` underscores. Removing underscores from the files is an anti-pattern for Sass, but we're doing this because we're proactively moving away from Sass to match CSS web standards. + +## Octicons + +We test for the proper use of the [octicons helper](../components/octicons/) in our templates and make sure that the symbols used are valid octicons. + +## IE rule limit + +We check that our compiled CSS assets don't contain more selectors than the [IE CSS selector limits](https://blogs.msdn.microsoft.com/ieinternals/2011/05/14/stylesheet-limits-in-internet-explorer/). We keep the rule limit in line with our [browser support](../#browser-support). diff --git a/docs/pages/css/tools/local-primer.md b/docs/pages/css/tools/local-primer.md new file mode 100644 index 00000000..939937b8 --- /dev/null +++ b/docs/pages/css/tools/local-primer.md @@ -0,0 +1,96 @@ +--- +title: Local development +doc_type: css +category: tools +--- + +When you are working with the `github/github` codebase, you can link Primer modules with your local development environment using the Primerize script. This will allow you to make changes to primer and see them reflected on `github.localhost` without the overhead of pulling in alpha releases of a package. + +## Prerequisites + +1. Working with `github/github` on the latest codebase. +2. Cloned down latest version of [primer/primer](https://github.com/primer/primer). +3. The `github/github` folder and the `primer/primer` folder must share the same parent folder. + +**Example:** +``` +~/codefolder/ +├── github +└── primer +``` + +## Linking to your local primer repository + +In your terminal start the server with the environment variable `LOCAL_PRIMER=1`. For example. + +``` +> LOCAL_PRIMER=1 script/server +``` + +When the variable is present, the script will check for linked local Primer packages. If it's not linked, then it will proceed to link the primer packages in `../primer` to your GitHub application. When the server starts with successfully linked packages, you will see a clear message. + +**Example output:** + +``` +❯ LOCAL_PRIMER=1 script/server +-------------------------------------------------------------------------------- + Development Primer is linked to the local Primer repository found here + /Users/usera/github/primer +-------------------------------------------------------------------------------- +14:09:14 web.1 | started with pid 36981 +14:09:14 assets.1 | started with pid 36982 +14:09:14 longpoll.1 | started with pid 36984 +14:09:14 git-daemon.1 | started with pid 36986 +14:09:14 gitauth.1 | started with pid 36988 +14:09:14 codeload.1 | started with pid 36991 +14:09:14 babeld.1 | started with pid 36996 +``` + +## Resetting github/github development assets + +To turn off Primerize, rerun `script/server` without the `LOCAL_PRIMER` flag. The script checks if you are still linked and restores everything to normal. + +**Example output:** + +``` +❯ script/server +-------------------------------------------------------------------------------- + Development Primer is linked to the local Primer repository found here + /Users/usera/github/primer +-------------------------------------------------------------------------------- +Turning off linked primer +extracting primer-alerts@1.5.5.tgz +extracting primer-avatars@1.5.2.tgz +extracting primer-base@1.7.0.tgz +extracting primer-blankslate@1.4.5.tgz +extracting primer-box@2.5.5.tgz +extracting primer-branch-name@1.0.3.tgz +extracting primer-breadcrumb@1.5.1.tgz +extracting primer-buttons@2.5.3.tgz +extracting primer-core@6.8.0.tgz +extracting primer-forms@2.1.0.tgz +extracting primer-labels@1.5.5.tgz +extracting primer-layout@1.4.5.tgz +extracting primer-markdown@3.7.5.tgz +extracting primer-marketing-buttons@1.0.4.tgz +extracting primer-marketing-support@1.5.0.tgz +extracting primer-marketing-type@1.4.5.tgz +extracting primer-marketing-utilities@1.6.1.tgz +extracting primer-marketing@6.2.0.tgz +extracting primer-navigation@1.5.3.tgz +extracting primer-page-headers@1.4.5.tgz +extracting primer-page-sections@1.4.5.tgz +extracting primer-popover@0.0.6.tgz +extracting primer-product@5.6.2.tgz +extracting primer-subhead@1.0.3.tgz +extracting primer-support@4.5.2.tgz +extracting primer-table-object@1.4.5.tgz +extracting primer-tables@1.4.5.tgz +extracting primer-tooltips@1.5.3.tgz +extracting primer-truncate@1.4.5.tgz +extracting primer-utilities@4.8.5.tgz +extracting primer@10.4.0.tgz +regenerating node binstubs +14:13:17 web.1 | started with pid 38585 +14:13:17 assets.1 | started with pid 38586 +``` diff --git a/docs/pages/css/tools/prototyping.md b/docs/pages/css/tools/prototyping.md new file mode 100644 index 00000000..bb7c98a4 --- /dev/null +++ b/docs/pages/css/tools/prototyping.md @@ -0,0 +1,37 @@ +--- +title: Prototyping +doc_type: css +category: tools +--- + +You're welcome to use whatever prototyping tool suits your needs, however we've set up some options that will help you get started quickly. + +The power of prototyping in code is that you can create clickable mocks that can be shared via a URL. This can be useful for exploring designs and interactions or for user research sessions. Prototypes can be throw-away, or part of your process for building out new features since you can work with the same CSS we use in production. + +## Simple HTML prototype with Primer +Copy the code below and paste it in a HTML file. The CDN link is always linked to the most up to date version of Primer and includes all of the modules in the core, product, and marketing packages. + +This method requires no dev environment set up and is useful for when you want to create simple prototypes using Primer. + +``` + + +
+