diff --git a/modules/primer-css/package.json b/modules/primer-css/package.json index 4f291aa61a..e0eb9bf212 100644 --- a/modules/primer-css/package.json +++ b/modules/primer-css/package.json @@ -54,7 +54,8 @@ "primer-tables": "1.4.1", "primer-tooltips": "1.4.1", "primer-truncate": "1.4.1", - "primer-utilities": "4.8.1" + "primer-utilities": "4.8.1", + "primer-popover": "0.0.1" }, "keywords": [ "primer", diff --git a/modules/primer-popover/LICENSE b/modules/primer-popover/LICENSE new file mode 100644 index 0000000000..61c8a4cffb --- /dev/null +++ b/modules/primer-popover/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/modules/primer-popover/README.md b/modules/primer-popover/README.md new file mode 100644 index 0000000000..3c34eaf701 --- /dev/null +++ b/modules/primer-popover/README.md @@ -0,0 +1,208 @@ +# Primer CSS Popover + +[![npm version](http://img.shields.io/npm/v/primer-popover.svg)](https://www.npmjs.org/package/primer-popover) +[![Build Status](https://travis-ci.org/primer/primer-css.svg?branch=master)](https://travis-ci.org/primer/primer-css) + +> Popover for suggesting, guiding, and bringing attention to specific UI elements on a page. + +This repository is a module of the full [primer-css][primer-css] repository. + +## Install + +This repository is distributed with [npm]. After [installing npm][install-npm], you can install `primer-popover` with this command. + +``` +$ npm install --save primer-popover +``` + +## Usage + +The source files included are written in [Sass][sass] (SCSS) You can simply point your sass `include-path` at your `node_modules` directory and import it like this. + +```scss +@import "primer-popover/index.scss"; +``` + +You can also import specific portions of the module by importing those partials from the `/lib/` folder. _Make sure you import any requirements along with the modules._ + +## Build + +For a compiled **CSS** version of this module, an npm script is included that will output a css version to `build/build.css` The built css file is also included in the npm package: + +``` +$ npm run build +``` + +## Documentation + + + +Popovers are used to bring attention to specific user interface elements, typically to suggest an action or to guide users through a new experience. + +{:toc} + +Popover's consist of: + +- The block element, `.Popover`, which simply positions its content absolutely atop other body content. +- The child element, `.Popover-message`, which contains the markup for the intended messaging and the visual "caret." + +In the examples below, `Popover-message`, in particular, uses a handful of utility classes to style it appropriately. And these are intended to demonstrate the default, go-to presentation for the popover's message. By default, the message's caret is centered on the top edge of the message. + +The `Popover-message` element also supports several modifiers, most of which position the caret differently: + +- `.Popover-message--top` (default): Places the caret on the top edge of the message, horizontally centered. +- `.Popover-message--bottom`: Places the caret on the bottom edge of the message, horizontally centered. +- `.Popover-message--right`: Places the caret on the right edge of the message, vertically centered. +- `.Popover-message--left`: Places the caret on the left edge of the message, vertically centered. + +Each of these modifiers also support a syntax for adjusting the positioning the caret to the right, left, top, or bottom of its respective edge. That syntax looks like: + +- `.Popover-message--top--right` +- `.Popover-message--right--top` +- `.Popover-message--bottom--left` +- `.Popover-message--left--bottom` + +Lastly, there is an added `.Popover-message--large` modifier, which assumes a slightly wider popover message on screens wider than 544px. + +### Notes + +The samples below include optional markup, like: +- An outermost container that establishes stacking context (e.g. `position-relative`). +- A choice piece of user interface (a button, in this case) to relate the popover to. +- Use of the `Details` and `js-details` family of class names, which interact with JavaScript to demonstrate dismissal of the popover by clicking the nested "Got it!" button. + +### Basic example +Defaults to caret oriented top-center. + +```html title="Default (top-center)" +
+ +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+
+``` + +### Large example + +```html title="Large" +
+ +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+
+``` + +### Top-right-aligned example + +```html title="Top-right" +
+ +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+
+``` + +### Top-right-aligned example + +```html title="Top-left" +
+ +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+
+``` + +### Right-aligned example + +```html title="Right" +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+``` + +### Left-aligned example + +```html title="Left" +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+``` + +### Bottom-aligned example + +```html title="Bottom" +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+``` + +### Bottom-right-aligned example + +```html title="Bottom-right" +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+``` + +### Bottom-left-aligned example + +```html title="Bottom-left" +
+
+

Popover heading

+

Message about this particular piece of UI.

+ +
+
+``` + + + +## License + +[MIT](./LICENSE) © [GitHub](https://github.com/) + +[primer-css]: https://github.com/primer/primer +[docs]: http://primercss.io/ +[npm]: https://www.npmjs.com/ +[install-npm]: https://docs.npmjs.com/getting-started/installing-node +[sass]: http://sass-lang.com/ diff --git a/modules/primer-popover/index.scss b/modules/primer-popover/index.scss new file mode 100644 index 0000000000..9187af06d8 --- /dev/null +++ b/modules/primer-popover/index.scss @@ -0,0 +1,3 @@ +// support files +@import "primer-support/index.scss"; +@import "./lib/popover.scss"; diff --git a/modules/primer-popover/lib/popover.scss b/modules/primer-popover/lib/popover.scss new file mode 100644 index 0000000000..aacd04d154 --- /dev/null +++ b/modules/primer-popover/lib/popover.scss @@ -0,0 +1,180 @@ +.Popover { + position: absolute; + z-index: 100; +} + +.Popover-message { + position: relative; + width: 232px; + margin-right: auto; + margin-left: auto; + + // Carets + &::before, + &::after { + position: absolute; + left: 50%; + display: inline-block; + content: ""; + } + + &::before { + top: -$spacer-3; + margin-left: -9px; + border: $spacer-2 $border-style transparent; + border-bottom-color: $border-black-fade; + } + + &::after { + top: -14px; + margin-left: -$spacer-2; + border: 7px $border-style transparent; + border-bottom-color: $bg-white; + } +} + +// Bottom-oriented carets +.Popover-message--bottom, +.Popover-message--bottom--right, +.Popover-message--bottom--left { + &::before, + &::after { + top: auto; + border-bottom-color: transparent; + } + + &::before { + bottom: -$spacer-3; + border-top-color: $border-black-fade; + } + + &::after { + bottom: -14px; + border-top-color: $bg-white; + } +} + +// Top & Bottom: Right-oriented carets +.Popover-message--top--right, +.Popover-message--bottom--right { + right: -9px; + margin-right: 0; + + &::before, + &::after { + left: auto; + margin-left: 0; + } + + &::before { + right: 20px; + } + + &::after { + right: 21px; + } +} + +// Top & Bottom: Left-oriented carets +.Popover-message--top--left, +.Popover-message--bottom--left { + left: -9px; + margin-left: 0; + + &::before, + &::after { + left: $spacer-4; + margin-left: 0; + } + + &::after { + left: 21px; + } +} + +// Right- & Left-oriented carets +.Popover-message--right, +.Popover-message--right--top, +.Popover-message--right--bottom, +.Popover-message--left, +.Popover-message--left--top, +.Popover-message--left--bottom { + &::before, + &::after { + top: 50%; + left: auto; + margin-left: 0; + border-bottom-color: transparent; + } + + &::before { + margin-top: -9px; + } + + &::after { + margin-top: -8px; + } +} + +// Right-oriented carets +.Popover-message--right, +.Popover-message--right--top, +.Popover-message--right--bottom { + &::before { + right: -$spacer-3; + border-left-color: $border-black-fade; + } + + &::after { + right: -14px; + border-left-color: $bg-white; + } +} + +// Left-oriented carets +.Popover-message--left, +.Popover-message--left--top, +.Popover-message--left--bottom { + &::before { + left: -$spacer-3; + border-right-color: $border-black-fade; + } + + &::after { + left: -14px; + border-right-color: $bg-white; + } +} + +// Right & Left: Top-oriented carets +.Popover-message--right--top, +.Popover-message--left--top { + &::before, + &::after { + top: $spacer-4; + } +} + +// Right & Left: Bottom-oriented carets +.Popover-message--right--bottom, +.Popover-message--left--bottom { + &::before, + &::after { + top: auto; + } + + &::before { + bottom: $spacer-4; + } + + &::after { + bottom: 21px; + } +} + +.Popover-message--large { + + @include breakpoint(sm) { + min-width: 320px; + } +} diff --git a/modules/primer-popover/package.json b/modules/primer-popover/package.json new file mode 100644 index 0000000000..76557d4f69 --- /dev/null +++ b/modules/primer-popover/package.json @@ -0,0 +1,35 @@ +{ + "version": "0.0.1", + "name": "primer-popover", + "description": "Popover for suggesting, guiding, and bringing attention to specific UI elements on a page.", + "homepage": "http://primercss.io/", + "primer": { + "category": "product", + "module_type": "components" + }, + "author": "GitHub, Inc.", + "license": "MIT", + "style": "index.scss", + "main": "build/index.js", + "repository": "https://github.com/primer/primer-css/tree/master/modules/primer-popover", + "bugs": { + "url": "https://github.com/primer/primer-css/issues" + }, + "scripts": { + "test-docs": "../../script/test-docs", + "build": "../../script/npm-run primer-module-build index.scss", + "prepare": "npm run build", + "lint": "../../script/lint-scss", + "test": "../../script/npm-run-all build lint test-docs" + }, + "dependencies": { + "primer-support": "4.4.1" + }, + "peerDependencies": { + "primer-box": "2.5.1" + }, + "keywords": [ + "github", + "primer" + ] +} diff --git a/modules/primer-popover/stories.js b/modules/primer-popover/stories.js new file mode 100644 index 0000000000..abf78092b0 --- /dev/null +++ b/modules/primer-popover/stories.js @@ -0,0 +1,10 @@ +import React from 'react' +import { storiesOf } from '@storybook/react' +import storiesFromMarkdown from '../../.storybook/lib/storiesFromMarkdown' + +const stories = storiesOf('Popover', module) + +storiesFromMarkdown(require.context('.', true, /\.md$/)) + .forEach(({title, story}) => { + stories.add(title, story) + }) diff --git a/modules/primer-product/index.scss b/modules/primer-product/index.scss index 7ef2d0c1e2..eac9978cc6 100644 --- a/modules/primer-product/index.scss +++ b/modules/primer-product/index.scss @@ -20,4 +20,5 @@ @import "primer-branch-name/index.scss"; @import "primer-labels/index.scss"; @import "primer-markdown/index.scss"; +@import "primer-popover/index.scss"; @import "primer-subhead/index.scss"; diff --git a/modules/primer-product/package.json b/modules/primer-product/package.json index 3a614ea852..7e43b3948a 100644 --- a/modules/primer-product/package.json +++ b/modules/primer-product/package.json @@ -32,6 +32,7 @@ "primer-branch-name": "0.0.1", "primer-labels": "1.5.1", "primer-markdown": "3.7.1", + "primer-popover": "0.0.1", "primer-subhead": "0.0.1", "primer-support": "4.4.1" }