diff --git a/.babelrc b/.babelrc deleted file mode 100644 index f2e312799..000000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["env", "stage-2"] -} diff --git a/.gitignore b/.gitignore index 6fb886d91..29d9977a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,73 @@ -node_modules/ -.cache/ -.DS_Store -dist/ -src_o/ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn +yarn-error.log +.pnp/ +.pnp.js + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# gatsby files +.cache/ +public + +# Mac files +.DS_Store \ No newline at end of file diff --git a/favicon-32x32.png b/favicon-32x32.png deleted file mode 100644 index 3ce4960e3..000000000 Binary files a/favicon-32x32.png and /dev/null differ diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index be253a024..000000000 Binary files a/favicon.ico and /dev/null differ diff --git a/index.html b/index.html deleted file mode 100644 index 77f3bd00e..000000000 --- a/index.html +++ /dev/null @@ -1,2901 +0,0 @@ - - - - - - 30 Seconds of CSS - - - - - - - - - - - - - - - - - - -
-
-
- - - -
- -

30 Seconds of CSS

-

- A curated collection of useful CSS snippets you can understand in 30 seconds or less. -

-
- Star -
-
-
-
-
-
- -
-

Bouncing loaderanimation

-

Creates a bouncing loader animation.

-

HTML

<div class="bouncing-loader">
-  <div></div>
-  <div></div>
-  <div></div>
-</div>
-
-

CSS

@keyframes bouncing-loader {
-  to {
-    opacity: 0.1;
-    transform: translate3d(0, -1rem, 0);
-  }
-}
-.bouncing-loader {
-  display: flex;
-  justify-content: center;
-}
-.bouncing-loader > div {
-  width: 1rem;
-  height: 1rem;
-  margin: 3rem 0.2rem;
-  background: #8385aa;
-  border-radius: 50%;
-  animation: bouncing-loader 0.6s infinite alternate;
-}
-.bouncing-loader > div:nth-child(2) {
-  animation-delay: 0.2s;
-}
-.bouncing-loader > div:nth-child(3) {
-  animation-delay: 0.4s;
-}
-
-

Demo

-
-
-
-
-
-
-
- -

Explanation

-

Note: 1rem is usually 16px.

-
    -
  1. -

    @keyframes defines an animation that has two states, where the element changes opacity and is translated up on the 2D plane using transform: translate3d(). Using a single axis translation on transform: translate3d() improves the performance of the animation.

    -
  2. -
  3. -

    .bouncing-loader is the parent container of the bouncing circles and uses display: flex - and justify-content: center to position them in the center.

    -
  4. -
  5. -

    .bouncing-loader > div, targets the three child divs of the parent to be styled. The divs are given a width and height of 1rem, using border-radius: 50% to turn them from squares to circles.

    -
  6. -
  7. -

    margin: 3rem 0.2rem specifies that each circle has a top/bottom margin of 3rem and left/right margin - of 0.2rem so that they do not directly touch each other, giving them some breathing room.

    -
  8. -
  9. -

    animation is a shorthand property for the various animation properties: animation-name, animation-duration, animation-iteration-count, animation-direction are used.

    -
  10. -
  11. -

    nth-child(n) targets the element which is the nth child of its parent.

    -
  12. -
  13. -

    animation-delay is used on the second and third div respectively, so that each element does not start the animation at the same time.

    -
  14. -
-

Browser support

-
-
- 97.4% -
-
- - - -
-
-

Box-sizing resetlayout

-

Resets the box-model so that widths and heights are not affected by their borders or padding.

-

HTML

<div class="box">border-box</div>
-<div class="box content-box">content-box</div>
-
-

CSS

html {
-  box-sizing: border-box;
-}
-*,
-*::before,
-*::after {
-  box-sizing: inherit;
-}
-.box {
-  display: inline-block;
-  width: 150px;
-  height: 150px;
-  padding: 10px;
-  background: tomato;
-  color: white;
-  border: 10px solid red;
-}
-.content-box {
-  box-sizing: content-box;
-}
-
-

Demo

-
-
border-box
-
content-box
-
- -

Explanation

-
    -
  1. box-sizing: border-box makes the addition of padding or borders not affect an element's width or height.
  2. -
  3. box-sizing: inherit makes an element respect its parent's box-sizing rule.
  4. -
-

Browser support

-
-
- 99.9% -
-
- - - -
-
-

Button border animationanimation

-

Creates a border animation on hover.

-

HTML

<div class="button-border"><button class="button">Submit</button></div>
-
-

CSS

.button {
-  background-color: #c47135;
-  border: none;
-  color: #ffffff;
-  outline: none;
-  padding: 12px 40px 10px;
-  position: relative;
-}
-.button:before,
-.button:after {
-  border: 0 solid transparent;
-  transition: all 0.25s;
-  content: '';
-  height: 24px;
-  position: absolute;
-  width: 24px;
-}
-.button:before {
-  border-top: 2px solid #c47135;
-  left: 0px;
-  top: -5px;
-}
-.button:after {
-  border-bottom: 2px solid #c47135;
-  bottom: -5px;
-  right: 0px;
-}
-.button:hover {
-  background-color: #c47135;
-}
-.button:hover:before,
-.button:hover:after {
-  height: 100%;
-  width: 100%;
-}
-
-

Demo

-
-
-
- -

Explanation

-

Use the :before and :after pseduo-elements as borders that animate on hover.

-

Browser support

-
-
- 100% -
-
- - - -
-
-

Calc()other

-

The function calc() allows to define CSS values with the use of mathematical expressions, the value adopted for the property is the result of a mathematical expression.

-

HTML

<div class="box-example"></div>
-
-

CSS

.box-example {
-  height: 280px;
-  background: #222 url('https://image.ibb.co/fUL9nS/wolf.png') no-repeat;
-  background-position: calc(100% - 20px) calc(100% - 20px);
-}
-
-

Demo

-
-
-
- -

If you want to align a background-image from right and bottom wasn't possible with just straight length values. - So now it's possible using calc():

-
-
Background-image in the right/bottom
-
- -

Explanation

-
    -
  1. It allows addition, subtraction, multiplication and division.
  2. -
  3. Can use different units (pixel and percent together, for example) for each value in your expression.
  4. -
  5. It is permitted to nest calc() functions.
  6. -
  7. It can be used in any property that <length>, <frequency>, <angle>, <time>, <number>, <color>, or <integer> is allowed, like width, height, font-size, top, left, etc.
  8. -
-

Browser support

-
-
- 97.0% -
-
- - - -
-
-

Circlevisual

-

Creates a circle shape with pure CSS.

-

HTML

<div class="circle"></div>
-
-

CSS

.circle {
-  border-radius: 50%;
-  width: 2rem;
-  height: 2rem;
-  background: #333;
-}
-
-

Demo

-
-
-
- -

Explanation

-

border-radius: 50% curves the borders of an element to create a circle.

-

Since a circle has the same radius at any given point, the width and height must be the same. Differing - values will create an ellipse.

-

Browser support

-
-
- 97.7% -
-
- - - -
-
-

Clearfixlayout

-

Ensures that an element self-clears its children.

-
Note: This is only useful if you are still using float to build layouts. Please consider using a modern approach with flexbox layout or grid layout.
-

HTML

<div class="clearfix">
-  <div class="floated">float a</div>
-  <div class="floated">float b</div>
-  <div class="floated">float c</div>
-</div>
-
-

CSS

.clearfix::after {
-  content: '';
-  display: block;
-  clear: both;
-}
-.floated {
-  float: left;
-}
-
-

Demo

-
-
-
float a
-
float b
-
float c
-
-
- -

Explanation

-
    -
  1. .clearfix::after defines a pseudo-element.
  2. -
  3. content: '' allows the pseudo-element to affect layout.
  4. -
  5. clear: both indicates that the left, right or both sides of the element cannot be adjacent - to earlier floated elements within the same block formatting context.
  6. -
-

Browser support

-
-
- 100% -
-
-

⚠️ For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).

- - -
-
-

Constant width to height ratiolayout

-

Given an element of variable width, it will ensure its height remains proportionate in a responsive fashion - (i.e., its width to height ratio remains constant).

-

HTML

<div class="constant-width-to-height-ratio"></div>
-
-

CSS

.constant-width-to-height-ratio {
-  background: #333;
-  width: 50%;
-}
-.constant-width-to-height-ratio::before {
-  content: '';
-  padding-top: 100%;
-  float: left;
-}
-.constant-width-to-height-ratio::after {
-  content: '';
-  display: block;
-  clear: both;
-}
-
-

Demo

-
-
-
- -

Explanation

-

padding-top on the ::before pseudo-element causes the height of the element to equal a percentage of - its width. 100% therefore means the element's height will always be 100% of the width, creating a responsive - square.

-

This method also allows content to be placed inside the element normally.

-

Browser support

-
-
- 100% -
-
- -
-
-

Countervisualother

-

Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.

-

HTML

<ul>
-  <li>List item</li>
-  <li>List item</li>
-  <li>
-    List item
-    <ul>
-      <li>List item</li>
-      <li>List item</li>
-      <li>List item</li>
-    </ul>
-  </li>
-</ul>
-
-

CSS

ul {
-  counter-reset: counter;
-}
-li::before {
-  counter-increment: counter;
-  content: counters(counter, '.') ' ';
-}
-
-

Demo

-
-
    -
  • List item
  • -
  • List item
  • -
  • - List item -
      -
    • List item
    • -
    • List item
    • -
    • List item
    • -
    -
  • -
-
- -

Explanation

-

You can create a ordered list using any type of HTML.

-
    -
  1. -

    counter-reset Initializes a counter, the value is the name of the counter. By default, the counter starts at 0. This property can also be used to change its value to any specific number.

    -
  2. -
  3. -

    counter-increment Used in element that will be countable. Once counter-reset initialized, a counter's value can be increased or decreased.

    -
  4. -
  5. -

    counter(name, style) Displays the value of a section counter. Generally used in a content property. This function can receive two parameters, the first as the name of the counter and the second one can be decimal or upper-roman (decimal by default).

    -
  6. -
  7. -

    counters(counter, string, style) Displays the value of a section counter. Generally used in a content property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be decimal or upper-roman (decimal by default).

    -
  8. -
  9. -

    A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the counters() function, separating text can be inserted between different levels of nested counters.

    -
  10. -
-

Browser support

-
-
- 99.9% -
-
- - - -
-
-

Custom scrollbarvisual

-

Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.

-

HTML

<div class="custom-scrollbar">
-  <p>
-    Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />
-    Iure id exercitationem nulla qui repellat laborum vitae, <br />
-    molestias tempora velit natus. Quas, assumenda nisi. <br />
-    Quisquam enim qui iure, consequatur velit sit?
-  </p>
-</div>
-
-

CSS

.custom-scrollbar {
-  height: 70px;
-  overflow-y: scroll;
-}
-/* To style the document scrollbar, remove `.custom-scrollbar` */
-.custom-scrollbar::-webkit-scrollbar {
-  width: 8px;
-}
-.custom-scrollbar::-webkit-scrollbar-track {
-  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
-  border-radius: 10px;
-}
-.custom-scrollbar::-webkit-scrollbar-thumb {
-  border-radius: 10px;
-  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
-}
-
-

Demo

-
-
-

- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit? -

-
-
- -

Explanation

-
    -
  1. ::-webkit-scrollbar targets the whole scrollbar element.
  2. -
  3. ::-webkit-scrollbar-track targets only the scrollbar track.
  4. -
  5. ::-webkit-scrollbar-thumb targets the scrollbar thumb.
  6. -
-

There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the WebKit Blog.

-

Browser support

-
-
- 90.7% -
-
-

⚠️ Scrollbar styling doesn't appear to be on any standards track.

- - - -
-
-

Custom text selectionvisual

-

Changes the styling of text selection.

-

HTML

<p class="custom-text-selection">Select some of this text.</p>
-
-

CSS

::selection {
-  background: aquamarine;
-  color: black;
-}
-.custom-text-selection::selection {
-  background: deeppink;
-  color: white;
-}
-
-

Demo

-
-

Select some of this text.

-
- -

Explanation

-

::selection defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.

-

Browser support

-
-
- 86.5% -
-
-

⚠️ Requires prefixes for full support and is not actually -in any specification.

- - - -
-
-

Custom variablesother

-

CSS variables that contain specific values to be reused throughout a document.

-

HTML

<p class="custom-variables">CSS is awesome!</p>
-
-

CSS

:root {
-  /* Place variables within here to use the variables globally. */
-}
-.custom-variables {
-  --some-color: #da7800;
-  --some-keyword: italic;
-  --some-size: 1.25em;
-  --some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
-  color: var(--some-color);
-  font-size: var(--some-size);
-  font-style: var(--some-keyword);
-  text-shadow: var(--some-complex-value);
-}
-
-

Demo

-
-

CSS is awesome!

-
- -

Explanation

-

The variables are defined globally within the :root CSS pseudo-class which matches the root element of a tree representing the document. Variables can also be scoped to a selector if defined within the block.

-

Declare a variable with --variable-name:.

-

Reuse variables throughout the document using the var(--variable-name) function.

-

Browser support

-
-
- 91.6% -
-
- - - -
-
-

Disable selectioninteractivity

-

Makes the content unselectable.

-

HTML

<p>You can select me.</p>
-<p class="unselectable">You can't select me!</p>
-
-

CSS

.unselectable {
-  user-select: none;
-}
-
-

Demo

-
-

You can select me.

-

You can't select me!

-
- -

Explanation

-

user-select: none specifies that the text cannot be selected.

-

Browser support

-
-
- 93.2% -
-
-

⚠️ Requires prefixes for full support. -
- ⚠️ This is not a secure method to prevent users from copying content.

- - - -
-
-

Display table centeringlayout

-

Vertically and horizontally centers a child element within its parent element using display: table (as an alternative to flexbox).

-

HTML

<div class="container">
-  <div class="center"><span>Centered content</span></div>
-</div>
-
-

CSS

.container {
-  border: 1px solid #333;
-  height: 250px;
-  width: 250px;
-}
-.center {
-  display: table;
-  height: 100%;
-  width: 100%;
-}
-.center > span {
-  display: table-cell;
-  text-align: center;
-  vertical-align: middle;
-}
-
-

Demo

-
-
-
Centered content
-
-
- -

Explanation

-
    -
  1. display: table on '.center' allows the element to behave like a <table> HTML element.
  2. -
  3. 100% height and width on '.center' allows the element to fill the available space within its parent element.
  4. -
  5. display: table-cell on '.center > span' allows the element to behave like an HTML element.
  6. -
  7. text-align: center on '.center > span' centers the child element horizontally.
  8. -
  9. vertical-align: middle on '.center > span' centers the child element vertically.
  10. -
-

The outer parent ('.container' in this case) must have a fixed height and width.

-

Browser support

-
-
- 100% -
-
- - - -
-
-

Donut spinneranimation

-

Creates a donut spinner that can be used to indicate the loading of content.

-

HTML

<div class="donut"></div>
-
-

CSS

@keyframes donut-spin {
-  0% {
-    transform: rotate(0deg);
-  }
-  100% {
-    transform: rotate(360deg);
-  }
-}
-.donut {
-  display: inline-block;
-  border: 4px solid rgba(0, 0, 0, 0.1);
-  border-left-color: #7983ff;
-  border-radius: 50%;
-  width: 30px;
-  height: 30px;
-  animation: donut-spin 1.2s linear infinite;
-}
-
-

Demo

-
-
-
- -

Explanation

-

Use a semi-transparent border for the whole element, except one side that will - serve as the loading indicator for the donut. Use animation to rotate the element.

-

Browser support

-
-
- 97.4% -
-
-

⚠️ Requires prefixes for full support.

- - - -
-
-

Dynamic shadowvisual

-

Creates a shadow similar to box-shadow but based on the colors of the element itself.

-

HTML

<div class="dynamic-shadow"></div>
-
-

CSS

.dynamic-shadow {
-  position: relative;
-  width: 10rem;
-  height: 10rem;
-  background: linear-gradient(75deg, #6d78ff, #00ffb8);
-  z-index: 1;
-}
-.dynamic-shadow::after {
-  content: '';
-  width: 100%;
-  height: 100%;
-  position: absolute;
-  background: inherit;
-  top: 0.5rem;
-  filter: blur(0.4rem);
-  opacity: 0.7;
-  z-index: -1;
-}
-
-

Demo

-
-
-
- -

Explanation

-
    -
  1. position: relative on the element establishes a Cartesian positioning context for psuedo-elements.
  2. -
  3. z-index: 1 establishes a new stacking context.
  4. -
  5. ::after defines a pseudo-element.
  6. -
  7. position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  8. -
  9. width: 100% and height: 100% sizes the pseudo-element to fill its parent's dimensions, making it equal in size.
  10. -
  11. background: inherit causes the pseudo-element to inherit the linear gradient specified on the element.
  12. -
  13. top: 0.5rem offsets the pseudo-element down slightly from its parent.
  14. -
  15. filter: blur(0.4rem) will blur the pseudo-element to create the appearance of a shadow underneath.
  16. -
  17. opacity: 0.7 makes the pseudo-element partially transparent.
  18. -
  19. z-index: -1 positions the pseudo-element behind the parent but in front of the background.
  20. -
-

Browser support

-
-
- 94.2% -
-
-

⚠️ Requires prefixes for full support.

- - - -
-
-

Easing variablesanimation

-

Variables that can be reused for transition-timing-function properties, more - powerful than the built-in ease, ease-in, ease-out and ease-in-out.

-

HTML

<div class="easing-variables">Hover</div>
-
-

CSS

:root {
-  /* Place variables in here to use globally */
-}
-.easing-variables {
-  --ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
-  --ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
-  --ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
-  --ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
-  --ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
-  --ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
-  --ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
-  --ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
-  --ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
-  --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
-  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
-  --ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
-  --ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
-  --ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
-  --ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
-  --ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
-  --ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
-  --ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
-  display: inline-block;
-  width: 75px;
-  height: 75px;
-  padding: 10px;
-  color: white;
-  line-height: 50px;
-  text-align: center;
-  background: #333;
-  transition: transform 1s var(--ease-out-quart);
-}
-.easing-variables:hover {
-  transform: rotate(45deg);
-}
-
-

Demo

-
-
Hover
-
- -

Explanation

-

The variables are defined globally within the :root CSS pseudo-class which matches the root element of a tree representing the document. In HTML, :root represents the <html> element and is identical to the selector html, except that its specificity is higher.

-

Browser support

-
-
- 91.6% -
-
- - - -
-
-

Etched textvisual

-

Creates an effect where text appears to be "etched" or engraved into the background.

-

HTML

<p class="etched-text">I appear etched into the background.</p>
-
-

CSS

.etched-text {
-  text-shadow: 0 2px white;
-  font-size: 1.5rem;
-  font-weight: bold;
-  color: #b8bec5;
-}
-
-

Demo

-
-

I appear etched into the background.

-
- -

Explanation

-

text-shadow: 0 2px white creates a white shadow offset 0px horizontally and 2px vertically - from the origin position.

-

The background must be darker than the shadow for the effect to work.

-

The text color should be slightly faded to make it look like it's engraved/carved out - of the background.

-

Browser support

-
-
- 99.5% -
-
- - - -
-
-

Evenly distributed childrenlayout

-

Evenly distributes child elements within a parent element.

-

HTML

<div class="evenly-distributed-children">
-  <p>Item1</p>
-  <p>Item2</p>
-  <p>Item3</p>
-</div>
-
-

CSS

.evenly-distributed-children {
-  display: flex;
-  justify-content: space-between;
-}
-
-

Demo

-
-
-

Item1

-

Item2

-

Item3

-
-
- -

Explanation

-
    -
  1. display: flex enables flexbox.
  2. -
  3. justify-content: space-between evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.
  4. -
-

Alternatively, use justify-content: space-around to distribute the children with space around them, rather than between them.

-

Browser support

-
-
- 99.5% -
-
-

⚠️ Needs prefixes for full support.

- - - -
-
-

Fit image in containerlayoutvisual

-

Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the background-size property.

-

HTML

<img class="image image-contain" src="https://picsum.photos/600/200" />
-<img class="image image-cover" src="https://picsum.photos/600/200" />
-
-

CSS

.image {
-  background: #34495e;
-  border: 1px solid #34495e;
-  width: 200px;
-  height: 200px;
-}
-.image-contain {
-  object-fit: contain;
-  object-position: center;
-}
-.image-cover {
-  object-fit: cover;
-  object-position: right top;
-}
-
-

Demo

-
-
- -

Explanation

-
    -
  • object-fit: contain fits the entire image within the container while preserving its aspect ratio.
  • -
  • object-fit: cover fills the container with the image while preserving its aspect ratio.
  • -
  • object-position: [x] [y] positions the image within the container.
  • -
-

Browser support

-
-
- 95.5% -
-
- - - - - -
-
-

Flexbox centeringlayout

-

Horizontally and vertically centers a child element within a parent element using flexbox.

-

HTML

<div class="flexbox-centering"><div class="child">Centered content.</div></div>
-
-

CSS

.flexbox-centering {
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  height: 100px;
-}
-
-

Demo

-
-
-
Centered content.
-
-
- -

Explanation

-
    -
  1. display: flex enables flexbox.
  2. -
  3. justify-content: center centers the child horizontally.
  4. -
  5. align-items: center centers the child vertically.
  6. -
-

Browser support

-
-
- 99.5% -
-
-

⚠️ Needs prefixes for full support.

- - - -
-
-

Focus Withinvisualinteractivity

-

Changes the appearance of a form if any of its children are focused.

-

HTML

<div class="focus-within">
-  <form>
-    <label for="given_name">Given Name:</label> <input id="given_name" type="text" /> <br />
-    <label for="family_name">Family Name:</label> <input id="family_name" type="text" />
-  </form>
-</div>
-
-

CSS

form {
-  border: 3px solid #2d98da;
-  color: #000000;
-  padding: 4px;
-}
-form:focus-within {
-  background: #f7b731;
-  color: #000000;
-}
-
-

Demo

-
-
-
-
- -
-
-
- - -

Explanation

-

The psuedo class :focus-within applies styles to a parent element if any child element gets focused. For example, an input element inside a form element.

-

Browser support

-
-
- 82.9% -
-
-

⚠️ Not supported in IE11 or the current version of Edge.

- - - - - -
-
-

Fullscreenvisual

-

The :fullscreen CSS pseudo-class represents an element that's displayed when the browser is in fullscreen mode.

-

HTML

<div class="container">
-  <p><em>Click the button below to enter the element into fullscreen mode. </em></p>
-  <div class="element" id="element"><p>I change color in fullscreen mode!</p></div>
-  <br />
-  <button onclick="var el = document.getElementById('element'); el.requestFullscreen();">
-    Go Full Screen!
-  </button>
-</div>
-
-

CSS

.container {
-  margin: 40px auto;
-  max-width: 700px;
-}
-.element {
-  padding: 20px;
-  height: 300px;
-  width: 100%;
-  background-color: skyblue;
-}
-.element p {
-  text-align: center;
-  color: white;
-  font-size: 3em;
-}
-.element:-ms-fullscreen p {
-  visibility: visible;
-}
-.element:fullscreen {
-  background-color: #e4708a;
-  width: 100vw;
-  height: 100vh;
-}
-
-

Demo

-
-
-

Click the button below to enter the element into fullscreen mode.

-
-

I change color in fullscreen mode!

-
-
- -
-
- -

Explanation

-
    -
  1. fullscreen CSS pseudo-class selector is used to select and style an element that is being displayed in fullscreen mode.
  2. -
-

Browser support

-
-
- 85.6% -
-
- - - -
-
-

Ghost tricklayout

-

Vertically centers an element in another.

-

HTML

<div class="ghost-trick">
-  <div class="ghosting"><p>Vertically centered without changing the position property.</p></div>
-</div>
-
-

CSS

.ghosting {
-  height: 300px;
-  background: #0ff;
-}
-.ghosting:before {
-  content: '';
-  display: inline-block;
-  height: 100%;
-  vertical-align: middle;
-}
-p {
-  display: inline-block;
-  vertical-align: middle;
-}
-
-

Demo

-
-
-
-

Vertically centered without changing the position property.

-
-
-
- -

Explanation

-

Use the style of a :before pseudo-element to vertically align inline elements without changing their position property.

-

Browser support

-
-
- 99.9% -
-
- - - -
-
-

Gradient textvisual

-

Gives text a gradient color.

-

HTML

<p class="gradient-text">Gradient text</p>
-
-

CSS

.gradient-text {
-  background: -webkit-linear-gradient(pink, red);
-  -webkit-text-fill-color: transparent;
-  -webkit-background-clip: text;
-}
-
-

Demo

-
-

Gradient text

-
- -

Explanation

-
    -
  1. background: -webkit-linear-gradient(...) gives the text element a gradient background.
  2. -
  3. webkit-text-fill-color: transparent fills the text with a transparent color.
  4. -
  5. webkit-background-clip: text clips the background with the text, filling the text with - the gradient background as the color.
  6. -
-

Browser support

-
-
- 94.1% -
-
-

⚠️ Uses non-standard properties.

- - - -
-
-

Grid centeringlayout

-

Horizontally and vertically centers a child element within a parent element using grid.

-

HTML

<div class="grid-centering"><div class="child">Centered content.</div></div>
-
-

CSS

.grid-centering {
-  display: grid;
-  justify-content: center;
-  align-items: center;
-  height: 100px;
-}
-
-

Demo

-
-
-
Centered content.
-
-
- -

Explanation

-
    -
  1. display: grid enables grid.
  2. -
  3. justify-content: center centers the child horizontally.
  4. -
  5. align-items: center centers the child vertically.
  6. -
-

Browser support

-
-
- 92.3% -
-
- - - -
-
-

Hairline bordervisual

-

Gives an element a border equal to 1 native device pixel in width, which can look - very sharp and crisp.

-

HTML

<div class="hairline-border">text</div>
-
-

CSS

.hairline-border {
-  box-shadow: 0 0 0 1px;
-}
-@media (min-resolution: 2dppx) {
-  .hairline-border {
-    box-shadow: 0 0 0 0.5px;
-  }
-}
-@media (min-resolution: 3dppx) {
-  .hairline-border {
-    box-shadow: 0 0 0 0.33333333px;
-  }
-}
-@media (min-resolution: 4dppx) {
-  .hairline-border {
-    box-shadow: 0 0 0 0.25px;
-  }
-}
-
-

Demo

-
-
text
-
- -

Explanation

-
    -
  1. box-shadow, when only using spread, adds a pseudo-border which can use subpixels*.
  2. -
  3. Use @media (min-resolution: ...) to check the device pixel ratio (1dppx equals 96 DPI), - setting the spread of the box-shadow equal to 1 / dppx.
  4. -
-

Browser Support

-
-
- 97.7% -
-
-

⚠️ Needs alternate syntax and JavaScript user agent checking for full support.

- -
-

*Chrome does not support subpixel values on border. Safari does not support subpixel values on box-shadow. Firefox supports subpixel values on both.

- - -
-
-

Height transitionanimation

-

Transitions an element's height from 0 to auto when its height is unknown.

-

HTML

<div class="trigger">
-  Hover me to see a height transition.
-  <div class="el">content</div>
-</div>
-
-

CSS

.el {
-  transition: max-height 0.5s;
-  overflow: hidden;
-  max-height: 0;
-}
-.trigger:hover > .el {
-  max-height: var(--max-height);
-}
-
-

JavaScript

var el = document.querySelector('.el')
-var height = el.scrollHeight
-el.style.setProperty('--max-height', height + 'px')
-
-

Demo

-
-
- Hover me to see a height transition. -
content
-
-
- - -

Explanation

-
CSS
-
    -
  1. transition: max-height: 0.5s cubic-bezier(...) specifies that changes to max-height should be transitioned over 0.5 seconds, using an ease-out-quint timing function.
  2. -
  3. overflow: hidden prevents the contents of the hidden element from overflowing its container.
  4. -
  5. max-height: 0 specifies that the element has no height initially.
  6. -
  7. .target:hover > .el specifies that when the parent is hovered over, target a child .el within - it and use the --max-height variable which was defined by JavaScript.
  8. -
-
JavaScript
-
    -
  1. el.scrollHeight is the height of the element including overflow, which will change dynamically - based on the content of the element.
  2. -
  3. el.style.setProperty(...) sets the --max-height CSS variable which is used to specify the max-height of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
  4. -
-

Browser Support

-
-
- 91.6% -
-
-

-
Requires JavaScript
- - ⚠️ Causes reflow on each animation frame, which will be laggy if there are a large number of elements - beneath the element that is transitioning in height. - -

- - - -
-
-

Hover shadow box animationanimation

-

Creates a shadow box around the text when it is hovered.

-

HTML

<p class="hover-shadow-box-animation">Box it!</p>
-
-

CSS

.hover-shadow-box-animation {
-  display: inline-block;
-  vertical-align: middle;
-  transform: perspective(1px) translateZ(0);
-  box-shadow: 0 0 1px transparent;
-  margin: 10px;
-  transition-duration: 0.3s;
-  transition-property: box-shadow, transform;
-}
-.hover-shadow-box-animation:hover,
-.hover-shadow-box-animation:focus,
-.hover-shadow-box-animation:active {
-  box-shadow: 1px 10px 10px -10px rgba(0, 0, 24, 0.5);
-  transform: scale(1.2);
-}
-
-

Demo

-
-

Box it!

-
- -

Explanation

-
    -
  1. display: inline-block to set width and length for p element thus making it an inline-block.
  2. -
  3. Set transform: perspective(1px) to give element a 3D space by affecting the distance between the Z plane and the user and translate(0) to reposition the p element along z-axis in 3D space.
  4. -
  5. box-shadow: to set up the box.
  6. -
  7. transparent to make box transparent.
  8. -
  9. transition-property to enable transitions for both box-shadow and transform.
  10. -
  11. :hover to activate whole css when hovering is done until active.
  12. -
  13. transform: scale(1.2) to change the scale, magnifying the text.
  14. -
-

Browser Support

-
-
- 97.3% -
-
- - - -
-
-

Hover underline animationanimation

-

Creates an animated underline effect when the text is hovered over.

-

Credit: https://flatuicolors.com/

-

HTML

<p class="hover-underline-animation">Hover this text to see the effect!</p>
-
-

CSS

.hover-underline-animation {
-  display: inline-block;
-  position: relative;
-  color: #0087ca;
-}
-.hover-underline-animation::after {
-  content: '';
-  position: absolute;
-  width: 100%;
-  transform: scaleX(0);
-  height: 2px;
-  bottom: 0;
-  left: 0;
-  background-color: #0087ca;
-  transform-origin: bottom right;
-  transition: transform 0.25s ease-out;
-}
-.hover-underline-animation:hover::after {
-  transform: scaleX(1);
-  transform-origin: bottom left;
-}
-
-

Demo

-
-

Hover this text to see the effect!

-
- -

Explanation

-
    -
  1. display: inline-block makes the block p an inline-block to prevent the underline from - spanning the entire parent width rather than just the content (text).
  2. -
  3. position: relative on the element establishes a Cartesian positioning context for pseudo-elements.
  4. -
  5. ::after defines a pseudo-element.
  6. -
  7. position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  8. -
  9. width: 100% ensures the pseudo-element spans the entire width of the text block.
  10. -
  11. transform: scaleX(0) initially scales the pseudo element to 0 so it has no width and is not visible.
  12. -
  13. bottom: 0 and left: 0 position it to the bottom left of the block.
  14. -
  15. transition: transform 0.25s ease-out means changes to transform will be transitioned over 0.25 seconds - with an ease-out timing function.
  16. -
  17. transform-origin: bottom right means the transform anchor point is positioned at the bottom right of the block.
  18. -
  19. :hover::after then uses scaleX(1) to transition the width to 100%, then changes the transform-origin - to bottom left so that the anchor point is reversed, allowing it transition out in the other direction when - hovered off.
  20. -
-

Browser support

-
-
- 97.5% -
-
- - - -
-
-

Last item with remaining available heightlayout

-

Take advantage of available viewport space by giving the last element the remaining available space in current viewport, even when resizing the window.

-

HTML

<div class="container">
-  <div>Div 1</div>
-  <div>Div 2</div>
-  <div>Div 3</div>
-</div>
-
-

CSS

html,
-body {
-  height: 100%;
-  margin: 0;
-}
-.container {
-  height: 100%;
-  display: flex;
-  flex-direction: column;
-}
-.container > div:last-child {
-  background-color: tomato;
-  flex: 1;
-}
-
-

Demo

-
-
-
Div 1
-
Div 2
-
Div 3
-
-
- -

Explanation

-
    -
  1. height: 100% set the height of container as viewport height.
  2. -
  3. display: flex enables flexbox.
  4. -
  5. flex-direction: column set the direction of flex items' order from top to down.
  6. -
  7. flex-grow: 1 the flexbox will apply remaining available space of container to last child element.
  8. -
-

The parent must have a viewport height. flex-grow: 1 could be applied to the first or second element, which will have all available space.

-

Browser support

-
-
- 99.5% -
-
-

⚠️ Needs prefixes for full support.

- - - - - -
-
-

Mouse cursor gradient trackingvisualinteractivity

-

A hover effect where the gradient follows the mouse cursor.

-

Credit: Tobias Reich

-

HTML

<button class="mouse-cursor-gradient-tracking"><span>Hover me</span></button>
-
-

CSS

.mouse-cursor-gradient-tracking {
-  position: relative;
-  background: #7983ff;
-  padding: 0.5rem 1rem;
-  font-size: 1.2rem;
-  border: none;
-  color: white;
-  cursor: pointer;
-  outline: none;
-  overflow: hidden;
-}
-.mouse-cursor-gradient-tracking span {
-  position: relative;
-}
-.mouse-cursor-gradient-tracking::before {
-  --size: 0;
-  content: '';
-  position: absolute;
-  left: var(--x);
-  top: var(--y);
-  width: var(--size);
-  height: var(--size);
-  background: radial-gradient(circle closest-side, pink, transparent);
-  transform: translate(-50%, -50%);
-  transition: width 0.2s ease, height 0.2s ease;
-}
-.mouse-cursor-gradient-tracking:hover::before {
-  --size: 200px;
-}
-
-

JavaScript

var btn = document.querySelector('.mouse-cursor-gradient-tracking')
-btn.onmousemove = function(e) {
-  var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
-  var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
-  btn.style.setProperty('--x', x + 'px')
-  btn.style.setProperty('--y', y + 'px')
-}
-
-

Demo

-
- - -

Explanation

-

TODO

-

Browser support

-
-
- 91.6% -
-
-

-
Requires JavaScript
- ⚠️ Requires JavaScript. -

- - - -
-
-

:not selectorvisual

-

The :not psuedo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.

-

HTML

<ul class="css-not-selector-shortcut">
-  <li>One</li>
-  <li>Two</li>
-  <li>Three</li>
-  <li>Four</li>
-</ul>
-
-

CSS

.css-not-selector-shortcut {
-  display: flex;
-}
-ul {
-  padding-left: 0;
-}
-li {
-  list-style-type: none;
-  margin: 0;
-  padding: 0 0.75rem;
-}
-li:not(:last-child) {
-  border-right: 2px solid #d2d5e4;
-}
-
-

Demo

-
-
    -
  • One
  • -
  • Two
  • -
  • Three
  • -
  • Four
  • -
-
- -

Explanation

-

li:not(:last-child) specifies that the styles should apply to all li elements except - the :last-child.

-

Browser support

-
-
- 99.9% -
-
- - - -
-
-

Offscreenlayoutvisual

-

A bulletproof way to completely hide an element visually and positionally in the DOM while still allowing it to be accessed by JavaScript and readable by screen readers. This method is very useful for accessibility (ADA) development when more context is needed for visually-impaired users. As an alternative to display: none which is not readable by screen readers or visibility: hidden which takes up physical space in the DOM.

-

HTML

<a class="button" href="http://pantswebsite.com">
-  Learn More <span class="offscreen"> about pants</span>
-</a>
-
-

CSS

.offscreen {
-  border: 0;
-  clip: rect(0 0 0 0);
-  height: 1px;
-  margin: -1px;
-  overflow: hidden;
-  padding: 0;
-  position: absolute;
-  width: 1px;
-}
-
-

Demo

- - -

Explanation

-
    -
  1. Remove all borders.
  2. -
  3. Use clip to indicate that no part of the element should be shown.
  4. -
  5. Make the height and width of the element 1px.
  6. -
  7. Negate the elements height and width using margin: -1px.
  8. -
  9. Hide the element's overflow.
  10. -
  11. Remove all padding.
  12. -
  13. Position the element absolutely so that it does not take up space in the DOM.
  14. -
-

Browser support

-
-
- 100% -
-
-

(Although clip technically has been depreciated, the newer clip-path currently has very limited browser support.)

- - - -
-
-

Overflow scroll gradientvisual

-

Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.

-

HTML

<div class="overflow-scroll-gradient">
-  <div class="overflow-scroll-gradient__scroller">
-    Lorem ipsum dolor sit amet consectetur adipisicing elit. <br />
-    Iure id exercitationem nulla qui repellat laborum vitae, <br />
-    molestias tempora velit natus. Quas, assumenda nisi. <br />
-    Quisquam enim qui iure, consequatur velit sit? <br />
-    Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />
-    Iure id exercitationem nulla qui repellat laborum vitae, <br />
-    molestias tempora velit natus. Quas, assumenda nisi. <br />
-    Quisquam enim qui iure, consequatur velit sit?
-  </div>
-</div>
-
-

CSS

.overflow-scroll-gradient {
-  position: relative;
-}
-.overflow-scroll-gradient::after {
-  content: '';
-  position: absolute;
-  bottom: 0;
-  width: 240px;
-  height: 25px;
-  background: linear-gradient(
-    rgba(255, 255, 255, 0.001),
-    white
-  ); /* transparent keyword is broken in Safari */
-  pointer-events: none;
-}
-.overflow-scroll-gradient__scroller {
-  overflow-y: scroll;
-  background: white;
-  width: 240px;
-  height: 200px;
-  padding: 15px;
-  line-height: 1.2;
-}
-
-

Demo

-
-
-
- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit?
- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit? -
-
-
- -

Explanation

-
    -
  1. position: relative on the parent establishes a Cartesian positioning context for pseudo-elements.
  2. -
  3. ::after defines a pseudo element.
  4. -
  5. background-image: linear-gradient(...) adds a linear gradient that fades from transparent to white - (top to bottom).
  6. -
  7. position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  8. -
  9. width: 240px matches the size of the scrolling element (which is a child of the parent that has - the pseudo element).
  10. -
  11. height: 25px is the height of the fading gradient pseudo-element, which should be kept relatively small.
  12. -
  13. bottom: 0 positions the pseudo-element at the bottom of the parent.
  14. -
  15. pointer-events: none specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.
  16. -
-

Browser support

-
-
- 97.5% -
-
- - - -
-
-

Popout menuinteractivity

-

Reveals an interactive popout menu on hover and focus.

-

HTML

<div class="reference" tabindex="0"><div class="popout-menu">Popout menu</div></div>
-
-

CSS

.reference {
-  position: relative;
-  background: tomato;
-  width: 100px;
-  height: 100px;
-}
-.popout-menu {
-  position: absolute;
-  visibility: hidden;
-  left: 100%;
-  background: #333;
-  color: white;
-  padding: 15px;
-}
-.reference:hover > .popout-menu,
-.reference:focus > .popout-menu,
-.reference:focus-within > .popout-menu {
-  visibility: visible;
-}
-
-

Demo

-
-
-
Popout menu
-
-
- -

Explanation

-
    -
  1. position: relative on the reference parent establishes a Cartesian positioning context for its child.
  2. -
  3. position: absolute takes the popout menu out of the flow of the document and positions it in relation to the parent.
  4. -
  5. left: 100% moves the the popout menu 100% of its parent's width from the left.
  6. -
  7. visibility: hidden hides the popout menu initially and allows for transitions (unlike display: none).
  8. -
  9. .reference:hover > .popout-menu means that when .reference is hovered over, select immediate children with a class of .popout-menu and change their visibility to visible, which shows the popout.
  10. -
  11. .reference:focus > .popout-menu means that when .reference is focused, the popout would be shown.
  12. -
  13. .reference:focus-within > .popout-menu ensures that the popout is shown when the focus is within the reference.
  14. -
-

Browser support

-
-
- 100% -
-
- -
-
-

Pretty text underlinevisual

-

A nicer alternative to text-decoration: underline or <u></u> where descenders do not clip the underline. - Natively implemented as text-decoration-skip-ink: auto but it has less control over the underline.

-

HTML

<p class="pretty-text-underline">Pretty text underline without clipping descending letters.</p>
-
-

CSS

.pretty-text-underline {
-  display: inline;
-  text-shadow: 1px 1px #f5f6f9, -1px 1px #f5f6f9, -1px -1px #f5f6f9, 1px -1px #f5f6f9;
-  background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
-  background-position: bottom;
-  background-repeat: no-repeat;
-  background-size: 100% 1px;
-}
-.pretty-text-underline::-moz-selection {
-  background-color: rgba(0, 150, 255, 0.3);
-  text-shadow: none;
-}
-.pretty-text-underline::selection {
-  background-color: rgba(0, 150, 255, 0.3);
-  text-shadow: none;
-}
-
-

Demo

-
-

Pretty text underline without clipping descending letters.

-
- -

Explanation

-
    -
  1. text-shadow uses 4 values with offsets that cover a 4x4 px area to ensure the underline - has a "thick" shadow that covers the line where descenders clip it. Use a color - that matches the background. For a larger font, use a larger px size. Additional values - can create an even thicker shadow, and subpixel values can also be used.
  2. -
  3. background-image: linear-gradient(...) creates a 90deg gradient using the - text color (currentColor).
  4. -
  5. The background-* properties size the gradient as 100% of the width of the block and 1px - in height at the bottom and disables repetition, which creates a 1px underline beneath - the text.
  6. -
  7. The ::selection pseudo selector rule ensures the text shadow does not interfere with text - selection.
  8. -
-

Browser support

-
-
- 97.5% -
-
- - - -
-
-

Reset all stylesvisual

-

Resets all styles to default values with one property. This will not affect direction and unicode-bidi properties.

-

HTML

<div class="reset-all-styles">
-  <h5>Title</h5>
-  <p>
-    Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui
-    repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui
-    iure, consequatur velit sit?
-  </p>
-</div>
-
-

CSS

.reset-all-styles {
-  all: initial;
-}
-
-

Demo

-
-
-
Title
-

- Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui - repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui - iure, consequatur velit sit? -

-
-
- -

Explanation

-

The all property allows you to reset all styles (inherited or not) to default values.

-

Browser support

-
-
- 91.2% -
-
-

⚠️ MS Edge status is under consideration.

- - - -
-
-

Shape separatorvisual

-

Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.

-

HTML

<div class="shape-separator"></div>
-
-

CSS

.shape-separator {
-  position: relative;
-  height: 48px;
-  background: #333;
-}
-.shape-separator::after {
-  content: '';
-  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12'%3E%3Cpath d='m12 0l12 12h-24z' fill='%23fff'/%3E%3C/svg%3E");
-  position: absolute;
-  width: 100%;
-  height: 12px;
-  bottom: 0;
-}
-
-

Demo

-
-
-
- -

Explanation

-
    -
  1. position: relative on the element establishes a Cartesian positioning context for pseudo elements.
  2. -
  3. ::after defines a pseudo element.
  4. -
  5. background-image: url(...) adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use the URL-encoder for SVG.
  6. -
  7. position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  8. -
  9. width: 100% ensures the element stretches the entire width of its parent.
  10. -
  11. height: 12px is the same height as the shape.
  12. -
  13. bottom: 0 positions the pseudo element at the bottom of the parent.
  14. -
-

Browser support

-
-
- 99.7% -
-
- - - -
-
-

Sibling fadeinteractivity

-

Fades out the siblings of a hovered item.

-

HTML

<div class="sibling-fade">
-  <span>Item 1</span> <span>Item 2</span> <span>Item 3</span> <span>Item 4</span>
-  <span>Item 5</span> <span>Item 6</span>
-</div>
-
-

CSS

span {
-  padding: 0 1rem;
-  transition: opacity 0.2s;
-}
-.sibling-fade:hover span:not(:hover) {
-  opacity: 0.5;
-}
-
-

Demo

-
-
- Item 1 Item 2 Item 3 Item 4 - Item 5 Item 6 -
-
- -

Explanation

-
    -
  1. transition: opacity 0.2s specifies that changes to opacity will be transitioned over 0.2 seconds.
  2. -
  3. .sibling-fade:hover span:not(:hover) specifies that when the parent is hovered, select any span children - that are not currently being hovered and change their opacity to 0.5.
  4. -
-

Browser support

-
-
- 97.5% -
-
- - - -
-
-

System font stackvisual

-

Uses the native font of the operating system to get close to a native app feel.

-

HTML

<p class="system-font-stack">This text uses the system font.</p>
-
-

CSS

.system-font-stack {
-  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
-    Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
-}
-
-

Demo

-
-

This text uses the system font.

-
- -

Explanation

-

The browser looks for each successive font, preferring the first one if possible, and - falls back to the next if it cannot find the font (on the system or defined in CSS).

-
    -
  1. -apple-system is San Francisco, used on iOS and macOS (not Chrome however)
  2. -
  3. BlinkMacSystemFont is San Francisco, used on macOS Chrome
  4. -
  5. Segoe UI is used on Windows 10
  6. -
  7. Roboto is used on Android
  8. -
  9. Oxygen-Sans is used on Linux with KDE
  10. -
  11. Ubuntu is used on Ubuntu (all variants)
  12. -
  13. Cantarell is used on Linux with GNOME Shell
  14. -
  15. "Helvetica Neue" and Helvetica is used on macOS 10.10 and below (wrapped in quotes because it has a space)
  16. -
  17. Arial is a font widely supported by all operating systems
  18. -
  19. sans-serif is the fallback sans-serif font if none of the other fonts are supported
  20. -
-

Browser support

-
-
- 100% -
-
- -
-
-

Toggle switchvisualinteractivity

-

Creates a toggle switch with CSS only.

-

HTML

<input type="checkbox" id="toggle" class="offscreen" /> <label for="toggle" class="switch"></label>
-
-

CSS

.switch {
-  position: relative;
-  display: inline-block;
-  width: 40px;
-  height: 20px;
-  background-color: rgba(0, 0, 0, 0.25);
-  border-radius: 20px;
-  transition: all 0.3s;
-}
-.switch::after {
-  content: '';
-  position: absolute;
-  width: 18px;
-  height: 18px;
-  border-radius: 18px;
-  background-color: white;
-  top: 1px;
-  left: 1px;
-  transition: all 0.3s;
-}
-input[type='checkbox']:checked + .switch::after {
-  transform: translateX(20px);
-}
-input[type='checkbox']:checked + .switch {
-  background-color: #7983ff;
-}
-.offscreen {
-  position: absolute;
-  left: -9999px;
-}
-
-

Demo

-
- -

Explanation

-

This effect is styling only the <label> element to look like a toggle switch, and hiding the actual <input> checkbox by positioning it offscreen. When clicking the label associated with the <input> element, it sets the <input> checkbox into the :checked state.

-
    -
  1. The for attribute associates the <label> with the appropriate <input> checkbox element by its id.
  2. -
  3. .switch::after defines a pseudo-element for the <label> to create the circular knob.
  4. -
  5. input[type='checkbox']:checked + .switch::after targets the <label>'s pseudo-element's style when the checkbox is checked.
  6. -
  7. transform: translateX(20px) moves the pseudo-element (knob) 20px to the right when the checkbox is checked.
  8. -
  9. background-color: #7983ff; sets the background-color of the switch to a different color when the checkbox is checked.
  10. -
  11. .offscreen moves the <input> checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.
  12. -
  13. transition: all 0.3s specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the <label>'s background-color and the pseudo-element's transform property when the checkbox is checked.
  14. -
-

Browser support

-
-
- 97.7% -
-
-

⚠️ Requires prefixes for full support.

- - - - - -
-
-

Transform centeringlayout

-

Vertically and horizontally centers a child element within its parent element using position: absolute and transform: translate() (as an alternative to flexbox or display: table). Similar to flexbox, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.

-

HTML

<div class="parent"><div class="child">Centered content</div></div>
-
-

CSS

.parent {
-  border: 1px solid #333;
-  height: 250px;
-  position: relative;
-  width: 250px;
-}
-.child {
-  left: 50%;
-  position: absolute;
-  top: 50%;
-  transform: translate(-50%, -50%);
-  text-align: center;
-}
-
-

Demo

-
-
-
Centered content
-
-
- -

Explanation

-
    -
  1. position: absolute on the child element allows it to be positioned based on its containing block.
  2. -
  3. left: 50% and top: 50% offsets the child 50% from the left and top edge of its containing block.
  4. -
  5. transform: translate(-50%, -50%) allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
  6. -
-

Note: Fixed height and width on parent element is for the demo only.

-

Browser support

-
-
- 97.7% -
-
-

⚠️ Requires prefix for full support.

- - - -
-
-

Trianglevisual

-

Creates a triangle shape with pure CSS.

-

HTML

<div class="triangle"></div>
-
-

CSS

.triangle {
-  width: 0;
-  height: 0;
-  border-top: 20px solid #333;
-  border-left: 20px solid transparent;
-  border-right: 20px solid transparent;
-}
-
-

Demo

-
-
-
- -

Explanation

-

View this link for a detailed explanation.

-

The color of the border is the color of the triangle. The side the triangle tip points - corresponds to the opposite border-* property. For example, a color on border-top - means the arrow points downward.

-

Experiment with the px values to change the proportion of the triangle.

-

Browser support

-
-
- 100% -
-
- -
-
-

Truncate text multilinelayout

-

If the text is longer than one line, it will be truncated for n lines and end with an gradient fade.

-

HTML

<p class="truncate-text-multiline">
-  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
-  labore et.
-</p>
-
-

CSS

.truncate-text-multiline {
-  overflow: hidden;
-  display: block;
-  height: 109.2px;
-  margin: 0 auto;
-  font-size: 26px;
-  line-height: 1.4;
-  width: 400px;
-  position: relative;
-}
-.truncate-text-multiline:after {
-  content: '';
-  position: absolute;
-  bottom: 0;
-  right: 0;
-  width: 150px;
-  height: 36.4px;
-  background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%);
-}
-
-

Demo

-
-

- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut - labore et. -

-
- -

Explanation

-
    -
  1. overflow: hidden prevents the text from overflowing its dimensions - (for a block, 100% width and auto height).
  2. -
  3. width: 400px ensures the element has a dimension.
  4. -
  5. height: 109.2px calculated value for height, it equals font-size * line-height * numberOfLines (in this case 26 * 1.4 * 3 = 109.2)
  6. -
  7. height: 36.4px calculated value for gradient container, it equals font-size * line-height (in this case 26 * 1.4 = 36.4)
  8. -
  9. background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%) gradient from transparent to #f5f6f9
  10. -
-

Browser support

-
-
- 97.5% -
-
- - - -
-
-

Truncate textlayout

-

If the text is longer than one line, it will be truncated and end with an ellipsis .

-

HTML

<p class="truncate-text">If I exceed one line's width, I will be truncated.</p>
-
-

CSS

.truncate-text {
-  overflow: hidden;
-  white-space: nowrap;
-  text-overflow: ellipsis;
-  width: 200px;
-}
-
-

Demo

-
-

If I exceed one line's width, I will be truncated.

-
- -

Explanation

-
    -
  1. overflow: hidden prevents the text from overflowing its dimensions - (for a block, 100% width and auto height).
  2. -
  3. white-space: nowrap prevents the text from exceeding one line in height.
  4. -
  5. text-overflow: ellipsis makes it so that if the text exceeds its dimensions, it - will end with an ellipsis.
  6. -
  7. width: 200px; ensures the element has a dimension, to know when to get ellipsis
  8. -
-

Browser support

-
-
- 99.8% -
-
-

⚠️ Only works for single line elements.

- - - -
-
-

Zebra striped listvisual

-

Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.

-

HTML

<ul>
-  <li>Item 01</li>
-  <li>Item 02</li>
-  <li>Item 03</li>
-  <li>Item 04</li>
-  <li>Item 05</li>
-</ul>
-
-

CSS

li:nth-child(odd) {
-  background-color: #eee;
-}
-
-

Demo

-
-
    -
  • Item 01
  • -
  • Item 02
  • -
  • Item 03
  • -
  • Item 04
  • -
  • Item 05
  • -
-
- -

Explanation

-
    -
  1. Use the :nth-child(odd) or :nth-child(even) pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.
  2. -
-

Note that you can use it to apply different styles to other HTML elements like div, tr, p, ol, etc.

-

Browser support

-
-
- 99.9% -
-
-

https://caniuse.com/#feat=css-sel3

- - - - -
-
-
-
- - diff --git a/src/docs/components/Meta.js b/src/docs/components/Meta.js new file mode 100644 index 000000000..c79e07669 --- /dev/null +++ b/src/docs/components/Meta.js @@ -0,0 +1,78 @@ +import React from 'react'; +import Helmet from 'react-helmet'; +import { useStaticQuery, graphql } from 'gatsby'; +require('../styles/index.scss'); // Do not change this to `import`, it's not going to work, no clue why + +// =================================================== +// Page metadata (using Helmet) +// =================================================== +const Meta = ({ description = '', lang = 'en', meta = [], title }) => { + const { site, file } = useStaticQuery( + graphql` + query { + site { + siteMetadata { + title + description + author + } + } + file(relativePath: { eq: "logo.png" }) { + id + childImageSharp { + fluid(maxHeight: 400) { + src + } + } + } + } + `, + ); + + const metaDescription = description || site.siteMetadata.description; + + return ( + + ); +}; + +export default Meta; diff --git a/src/docs/components/SVGs/BackArrowIcon.js b/src/docs/components/SVGs/BackArrowIcon.js new file mode 100644 index 000000000..789edf859 --- /dev/null +++ b/src/docs/components/SVGs/BackArrowIcon.js @@ -0,0 +1,22 @@ +import React from 'react'; + +const BackArrowIcon = ({ className, onClick }) => ( + + + + +); + +export default BackArrowIcon; diff --git a/src/docs/components/SVGs/ClipboardIcon.js b/src/docs/components/SVGs/ClipboardIcon.js new file mode 100644 index 000000000..e57f84b37 --- /dev/null +++ b/src/docs/components/SVGs/ClipboardIcon.js @@ -0,0 +1,22 @@ +import React from 'react'; + +const ClipboardIcon = ({ className, onClick }) => ( + + + + +); + +export default ClipboardIcon; diff --git a/src/docs/components/SVGs/CollapseClosedIcon.js b/src/docs/components/SVGs/CollapseClosedIcon.js new file mode 100644 index 000000000..a72270988 --- /dev/null +++ b/src/docs/components/SVGs/CollapseClosedIcon.js @@ -0,0 +1,23 @@ +import React from 'react'; + +const CollapseClosedIcon = ({ className, onClick }) => ( + + + + + +); + +export default CollapseClosedIcon; diff --git a/src/docs/components/SVGs/CollapseOpenIcon.js b/src/docs/components/SVGs/CollapseOpenIcon.js new file mode 100644 index 000000000..bcd04cb22 --- /dev/null +++ b/src/docs/components/SVGs/CollapseOpenIcon.js @@ -0,0 +1,22 @@ +import React from 'react'; + +const CollapseOpenIcon = ({ className, onClick }) => ( + + + + +); + +export default CollapseOpenIcon; diff --git a/src/docs/components/SVGs/DarkModeIcon.js b/src/docs/components/SVGs/DarkModeIcon.js new file mode 100644 index 000000000..318423094 --- /dev/null +++ b/src/docs/components/SVGs/DarkModeIcon.js @@ -0,0 +1,21 @@ +import React from 'react'; + +const DarkModeIcon = ({ className, onClick }) => ( + + + +); + +export default DarkModeIcon; diff --git a/src/docs/components/SVGs/GithubIcon.js b/src/docs/components/SVGs/GithubIcon.js new file mode 100644 index 000000000..5d2b2bb25 --- /dev/null +++ b/src/docs/components/SVGs/GithubIcon.js @@ -0,0 +1,21 @@ +import React from 'react'; + +const GithubIcon = ({ className, onClick }) => ( + + + +); + +export default GithubIcon; diff --git a/src/docs/components/SVGs/LightModeIcon.js b/src/docs/components/SVGs/LightModeIcon.js new file mode 100644 index 000000000..bb13cb19e --- /dev/null +++ b/src/docs/components/SVGs/LightModeIcon.js @@ -0,0 +1,29 @@ +import React from 'react'; + +const LightModeIcon = ({ className, onClick }) => ( + + + + + + + + + + + +); + +export default LightModeIcon; diff --git a/src/docs/components/SVGs/ListIcon.js b/src/docs/components/SVGs/ListIcon.js new file mode 100644 index 000000000..853b1a7b2 --- /dev/null +++ b/src/docs/components/SVGs/ListIcon.js @@ -0,0 +1,26 @@ +import React from 'react'; + +const ListIcon = ({ className, onClick }) => ( + + + + + + + + +); + +export default ListIcon; diff --git a/src/docs/components/SVGs/SearchIcon.js b/src/docs/components/SVGs/SearchIcon.js new file mode 100644 index 000000000..763ae3ea9 --- /dev/null +++ b/src/docs/components/SVGs/SearchIcon.js @@ -0,0 +1,24 @@ +import React from 'react'; + +const SearchIcon = ({ className, onClick }) => { + return ( + + + + + ); +}; + +export default SearchIcon; diff --git a/src/docs/components/SVGs/ShareIcon.js b/src/docs/components/SVGs/ShareIcon.js new file mode 100644 index 000000000..8e78b671e --- /dev/null +++ b/src/docs/components/SVGs/ShareIcon.js @@ -0,0 +1,25 @@ +import React from 'react'; + +const ShareIcon = ({ className, onClick }) => ( + + + + + + + +); + +export default ShareIcon; diff --git a/src/docs/components/Search.js b/src/docs/components/Search.js new file mode 100644 index 000000000..5b2903d43 --- /dev/null +++ b/src/docs/components/Search.js @@ -0,0 +1,28 @@ +import React from 'react'; + +// =================================================== +// Simple, stateful search component +// =================================================== +const Search = ({ defaultValue = '', setSearchQuery, className = '' }) => { + const [value, setValue] = React.useState(defaultValue); + + React.useEffect(() => { + setSearchQuery(value); + }, [value]); + + return ( + { + setValue(e.target.value); + }} + /> + ); +}; + +export default Search; diff --git a/src/docs/components/Shell.js b/src/docs/components/Shell.js new file mode 100644 index 000000000..988edf6e1 --- /dev/null +++ b/src/docs/components/Shell.js @@ -0,0 +1,149 @@ +import React from 'react'; +import { graphql, useStaticQuery } from 'gatsby'; +import { connect } from 'react-redux'; +import AniLink from 'gatsby-plugin-transition-link/AniLink'; +import ReactCSSTransitionReplace from 'react-css-transition-replace'; +import config from '../../../config'; + +import { toggleDarkMode } from '../state/app'; + +import SearchIcon from './SVGs/SearchIcon'; +import GithubIcon from './SVGs/GithubIcon'; +import DarkModeIcon from './SVGs/DarkModeIcon'; +import LightModeIcon from './SVGs/LightModeIcon'; +import ListIcon from './SVGs/ListIcon'; + +// =================================================== +// Application-level UI component +// =================================================== +const Shell = ({ + isDarkMode, + isSearch, + isList, + dispatch, + withIcon = true, + withTitle = true, + children, +}) => { + const data = useStaticQuery(graphql` + query SiteTitleQuery { + site { + siteMetadata { + title + description + } + } + file(relativePath: { eq: "30s-icon.png" }) { + id + childImageSharp { + original { + src + } + } + } + snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) { + data { + title + id + attributes { + tags + } + } + } + } + `); + let viewportWidth = typeof window !== 'undefined' && window.innerWidth; + + return ( +
+ {/* Menu */} +
+ + + + + + + {/* eslint-disable-next-line */} + + + + {/* + The use of React.Fragment here will cause a lot of errors to show up in webber:dev. + Truth is, this is the only decent way I found to deal with this module's odd behavior. + Keep as is, unless you can provide a better solution, in which case please send a PR. + */} + + {isDarkMode ? ( + dispatch(toggleDarkMode(!isDarkMode))} + /> + ) : ( + dispatch(toggleDarkMode(!isDarkMode))} + /> + )} + +
+ {/* Content */} +
+ {withTitle ? ( +

+ {data.site.siteMetadata.title} + {withIcon ? ( + Logo + ) : ( + '' + )} +

+ ) : ( + '' + )} + {children} +
+
+ ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(Shell); diff --git a/src/docs/components/SimpleCard.js b/src/docs/components/SimpleCard.js new file mode 100644 index 000000000..cd93b6af9 --- /dev/null +++ b/src/docs/components/SimpleCard.js @@ -0,0 +1,21 @@ +import React from 'react'; + +// =================================================== +// Generic card (displays textual content) +// =================================================== +const SimpleCard = ({ + title, + children, + isDarkMode +}) => ( +
+

+ {title} +

+
+ {children} +
+
+); + +export default SimpleCard; diff --git a/src/docs/components/SnippetCard.js b/src/docs/components/SnippetCard.js new file mode 100644 index 000000000..0f606caa3 --- /dev/null +++ b/src/docs/components/SnippetCard.js @@ -0,0 +1,167 @@ +import React from 'react'; +import { CopyToClipboard } from 'react-copy-to-clipboard'; +import config from '../../../config'; + +import { getTextualContent, getCodeBlocks, optimizeAllNodes } from '../util'; +// import ShareIcon from './SVGs/ShareIcon'; +import AniLink from 'gatsby-plugin-transition-link/AniLink'; +import CollapseOpenIcon from './SVGs/CollapseOpenIcon'; +import CollapseClosedIcon from './SVGs/CollapseClosedIcon'; +import ReactCSSTransitionReplace from 'react-css-transition-replace'; + +// =================================================== +// Snippet Card HOC - check components below for more +// =================================================== +const SnippetCard = ({ short, snippetData, ...rest }) => { + let difficulty = snippetData.tags.includes('advanced') + ? 'advanced' + : snippetData.tags.includes('beginner') + ? 'beginner' + : 'intermediate'; + return short ? ( + + ) : ( + + ); +}; + +// =================================================== +// Simple card corner for difficulty display +// =================================================== +const CardCorner = ({ difficulty = 'intermediate' }) => ( +
+); + +// =================================================== +// Full snippet view (tags, code, title, description) +// =================================================== +const FullCard = ({ snippetData, difficulty, isDarkMode }) => { + const [examplesOpen, setExamplesOpen] = React.useState(false); + const tags = snippetData.tags; + let cardCodeHtml = `${optimizeAllNodes( + getCodeBlocks(snippetData.html).html, + )}`; + let cardCodeCss = `${optimizeAllNodes( + getCodeBlocks(snippetData.html).css, + )}`; + let cardCodeJs = `${optimizeAllNodes( + getCodeBlocks(snippetData.html).js, + )}`; + return ( +
+ +

{snippetData.title}

+ {tags.map(tag => ( + {tag} + ))} +
+
+
+        
+        {
+          cardCodeJs && 
+        }
+        {/* 
+        
+          {examplesOpen && (
+            
+          )}
+         */}
+      
+
+ ); +}; + +// =================================================== +// Short snippet view (title, description, code*) +// =================================================== +const ShortCard = ({ + snippetData, + withCode = false, + difficulty, + isDarkMode +}) => { + let cardCodeHtml; + if (withCode) + cardCodeHtml = `${optimizeAllNodes( + getCodeBlocks(snippetData.html).code, + )}`; + return ( +
+ +

+ + {snippetData.title} + +

+
+ {withCode ?
+ { + let tst = document.createElement('div'); + tst.classList = 'toast'; + tst.innerHTML = 'Snippet copied to clipboard!'; + document.body.appendChild(tst); + setTimeout(function() { + tst.style.opacity = 0; + setTimeout(function() { + document.body.removeChild(tst); + }, 300); + }, 1700); + }} + > +
: '' } +
+ ); +}; + +export default SnippetCard; diff --git a/src/docs/pages/404.js b/src/docs/pages/404.js new file mode 100644 index 000000000..5239aa371 --- /dev/null +++ b/src/docs/pages/404.js @@ -0,0 +1,60 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import AniLink from 'gatsby-plugin-transition-link/AniLink'; + +import Shell from '../components/Shell'; +import Meta from '../components/Meta'; + +// =================================================== +// Not found page +// =================================================== +const NotFoundPage = ({ isDarkMode }) => ( + <> + + +

404

+
+

+ Page not found +
+

+

+ Seems like you have reached a page that does not exist. +

+ + + + + +   Go home + +
+
+ +); + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(NotFoundPage); diff --git a/src/docs/pages/about.js b/src/docs/pages/about.js new file mode 100644 index 000000000..e7fed6886 --- /dev/null +++ b/src/docs/pages/about.js @@ -0,0 +1,99 @@ +import React from 'react'; +import { connect } from 'react-redux'; + +import Shell from '../components/Shell'; +import Meta from '../components/Meta'; +import SimpleCard from '../components/SimpleCard'; + +// =================================================== +// About page +// =================================================== +const AboutPage = ({ isDarkMode }) => ( + <> + + +

About

+

+ A few word about us, our goals and our projects. +

+ +

+ The core goal of 30 seconds is to provide a quality resource for beginner and advanced developers alike. We want to help improve the software development ecosystem, by lowering the barrier of entry for newcomers and help seasoned veterans pick up new tricks and remember old ones. +

+

+ In order to achieve this, we have collected hundreds of snippets that can be of use in a wide range of situations. We welcome new contributors and we like fresh ideas, as long as the code is short and easy to grasp in about 30 seconds. +

+

+ The only catch, if you may, is that a few of our snippets are not perfectly optimized for large, enterprise applications and they might not be deemed production-ready. +

+
+ +

+ The 30 seconds movement started back in December, 2017, with the release of 30 seconds of code by Angelos Chalaris. Since then, hundreds of developers have contributed snippets to over 6 repositories, creating a thriving community of people willing to help each other write better code. +

+

+ In late 2018, the 30 seconds organization was formed on GitHub, in order to expand upon existing projects and ensure that they will remain high-quality resources in the future. +

+
+ +

+ The 30 seconds movement and, to some extent, the associated GitHub organization consists of all the people who have invested time and ideas to be part of this amazing community. Meanwhile, these fine folks are currently responsible for maintaining the codebases and dealing with organizational matters: +

+
+ +
+ fejes713 + Stefan Fejes +
+
+ flxwu + Felix Wu +
+
+ atomiks + atomiks +
+
+
+ + + +
+ sohelamin + Sohel Amin +
+
+
+ +

+ In order for the code provided via the 30 seconds projects to be as accessible and useful as possible, all of the snippets in these collections are licensed under the CC0-1.0 License meaning they are absolutely free to use in any project you like. If you like what we do, you can always credit us, but that is not mandatory. +

+

+ Logos, names and trademarks are not to be used without the explicit consent of the maintainers or owners of the 30 seconds GitHub organization. The only exception to this is the usage of the 30-seconds-of- name in open source projects, licensed under the CC0-1.0 License and hosted on GitHub, if their README and website clearly states that they are unofficial projects and in no way affiliated with the organization. +

+
+
+ +); + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(AboutPage); diff --git a/src/docs/pages/index.js b/src/docs/pages/index.js new file mode 100644 index 000000000..5e8d7daf2 --- /dev/null +++ b/src/docs/pages/index.js @@ -0,0 +1,159 @@ +import React from 'react'; +import { graphql } from 'gatsby'; +import { connect } from 'react-redux'; +import { pushNewPage, pushNewQuery } from '../state/app'; + +import Shell from '../components/Shell'; +import Meta from '../components/Meta'; +import Search from '../components/Search'; +import SnippetCard from '../components/SnippetCard'; + +import { getRawCodeBlocks as getCodeBlocks } from '../util'; + +// =================================================== +// Home page (splash and search) +// =================================================== +const IndexPage = props => { + const snippets = props.data.snippetDataJson.data.map(snippet => ({ + title: snippet.title, + html: props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.html, + tags: snippet.attributes.tags, + text: snippet.attributes.text, + id: snippet.id, + code: getCodeBlocks( + props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.rawMarkdownBody, + ).code, + })); + + const [searchQuery, setSearchQuery] = React.useState(props.searchQuery); + const [searchResults, setSearchResults] = React.useState(snippets); + + React.useEffect(() => { + props.dispatch(pushNewQuery(searchQuery)); + let q = searchQuery.toLowerCase(); + let results = snippets; + if (q.trim().length) + results = snippets.filter( + v => + v.tags.filter(t => t.indexOf(q) !== -1).length || + v.title.toLowerCase().indexOf(q) !== -1, + ); + setSearchResults(results); + }, [searchQuery]); + + React.useEffect(() => { + props.dispatch(pushNewPage('Search', '/search')); + }, []); + + return ( + <> + + + Logo +

{props.data.site.siteMetadata.title}

+

+ {props.data.site.siteMetadata.description} +

+ + {searchQuery.length === 0 ? ( +

+ Start typing a keyword to see matching snippets. +

+ ) : searchResults.length === 0 ? ( +

+ We couldn't find any results for the keyword{' '} + {searchQuery}. +

+ ) : ( + <> +

+ Click on a snippet's name to view its code. +

+

Search results

+ {searchResults.map(snippet => ( + + ))} + + )} +
+ + ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(IndexPage); + +export const indexPageQuery = graphql` + query snippetList { + site { + siteMetadata { + title + description + author + } + } + file(relativePath: { eq: "30s-icon.png" }) { + id + childImageSharp { + original { + src + } + } + } + snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) { + data { + id + title + attributes { + tags + text + } + } + } + allMarkdownRemark( + limit: 1000 + sort: { fields: [frontmatter___title], order: ASC } + ) { + totalCount + edges { + node { + id + html + rawMarkdownBody + fields { + slug + } + frontmatter { + title + tags + } + } + } + } + } +`; diff --git a/src/docs/pages/list.js b/src/docs/pages/list.js new file mode 100644 index 000000000..e3e52d798 --- /dev/null +++ b/src/docs/pages/list.js @@ -0,0 +1,148 @@ +import React from 'react'; +import { graphql } from 'gatsby'; +import { connect } from 'react-redux'; +import { pushNewPage } from '../state/app'; +import { capitalize } from '../util'; + +import Shell from '../components/Shell'; +import Meta from '../components/Meta'; +import AniLink from 'gatsby-plugin-transition-link/AniLink'; +import SnippetCard from '../components/SnippetCard'; + +import { getRawCodeBlocks as getCodeBlocks } from '../util'; +import SimpleCard from '../components/SimpleCard'; + +// =================================================== +// Snippet list page +// =================================================== +const ListPage = props => { + const snippets = props.data.snippetDataJson.data.map(snippet => ({ + title: snippet.title, + html: props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.html, + tags: snippet.attributes.tags, + text: snippet.attributes.text, + id: snippet.id, + code: getCodeBlocks( + props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.rawMarkdownBody, + ).code, + })); + const tags = snippets.reduce((acc, snippet) => { + if (!snippet.tags) return acc; + const primaryTag = snippet.tags[0]; + if (!acc.includes(primaryTag)) acc.push(primaryTag); + return acc; + }, []); + const staticPages = [ + { + url: 'about', + title: 'About', + description: 'A few word about us, our goals and our projects.' + } + ]; + + React.useEffect(() => { + props.dispatch(pushNewPage('Snippet List', '/list')); + }, []); + + return ( + <> + + +

Snippet List

+

+ Click on a snippet’s name to view its code or a tag name to view all + snippets in that category. +

+ {tags.map(tag => ( + <> +

+ + {capitalize(tag)} + +

+ {snippets + .filter(snippet => snippet.tags[0] === tag) + .map(snippet => ( + + ))} + + ))} +
+ {staticPages.map(page => ( + + {page.title} + + )} + > +

{page.description}

+
+ ))} +
+ + ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(ListPage); + +export const listPageQuery = graphql` + query snippetListing { + snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) { + data { + id + title + attributes { + tags + text + } + } + } + allMarkdownRemark( + limit: 1000 + sort: { fields: [frontmatter___title], order: ASC } + ) { + totalCount + edges { + node { + id + html + rawMarkdownBody + fields { + slug + } + frontmatter { + title + tags + } + } + } + } + } +`; diff --git a/src/docs/pages/search.js b/src/docs/pages/search.js new file mode 100644 index 000000000..33617e9b1 --- /dev/null +++ b/src/docs/pages/search.js @@ -0,0 +1,144 @@ +import React from 'react'; +import { graphql } from 'gatsby'; +import { connect } from 'react-redux'; +import { pushNewPage, pushNewQuery } from '../state/app'; + +import Shell from '../components/Shell'; +import Meta from '../components/Meta'; +import Search from '../components/Search'; +import SnippetCard from '../components/SnippetCard'; + +import { getRawCodeBlocks as getCodeBlocks } from '../util'; + +// =================================================== +// Search page +// =================================================== +const SearchPage = props => { + const snippets = props.data.snippetDataJson.data.map(snippet => ({ + title: snippet.title, + html: props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.html, + tags: snippet.attributes.tags, + text: snippet.attributes.text, + id: snippet.id, + code: getCodeBlocks( + props.data.allMarkdownRemark.edges.find( + v => v.node.frontmatter.title === snippet.title, + ).node.rawMarkdownBody, + ).code, + })); + + const [searchQuery, setSearchQuery] = React.useState(props.searchQuery); + const [searchResults, setSearchResults] = React.useState(snippets); + + React.useEffect(() => { + props.dispatch(pushNewQuery(searchQuery)); + let q = searchQuery.toLowerCase(); + let results = snippets; + if (q.trim().length) + results = snippets.filter( + v => + v.tags.filter(t => t.indexOf(q) !== -1).length || + v.title.toLowerCase().indexOf(q) !== -1, + ); + setSearchResults(results); + }, [searchQuery]); + + React.useEffect(() => { + props.dispatch(pushNewPage('Search', '/search')); + }, []); + + return ( + <> + + + +

Click on a snippet's name to view its code.

+ {/* Display page background or results depending on state */} + {searchQuery.length === 0 ? ( + <> +
+

+ Start typing a keyword to see matching snippets. +

+
+ + ) : searchResults.length === 0 ? ( + <> +
+

+ No results found +
+

+

+ We couldn't find any results for the keyword{' '} + {searchQuery}. +

+
+ + ) : ( + <> +

Search results

+ {searchResults.map(snippet => ( + + ))} + + )} +
+ + ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(SearchPage); + +export const searchPageQuery = graphql` + query searchSnippetList { + snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) { + data { + id + title + attributes { + tags + text + } + } + } + allMarkdownRemark( + limit: 1000 + sort: { fields: [frontmatter___title], order: ASC } + ) { + totalCount + edges { + node { + id + html + rawMarkdownBody + fields { + slug + } + frontmatter { + title + tags + } + } + } + } + } +`; diff --git a/src/docs/state/ReduxWrapper.js b/src/docs/state/ReduxWrapper.js new file mode 100644 index 000000000..5daacf556 --- /dev/null +++ b/src/docs/state/ReduxWrapper.js @@ -0,0 +1,13 @@ +import React from 'react'; +import { Provider } from 'react-redux'; +import { createStore as reduxCreateStore } from 'redux'; +import rootReducer from '.'; + +const createStore = () => reduxCreateStore(rootReducer); + +// =================================================== +// Wrapper for Gatsby +// =================================================== +export default ({ element }) => ( + {element} +); diff --git a/src/docs/state/app.js b/src/docs/state/app.js new file mode 100644 index 000000000..546e6fde4 --- /dev/null +++ b/src/docs/state/app.js @@ -0,0 +1,49 @@ +// Defalt state +const initialState = { + isDarkMode: false, + lastPageTitle: 'Home', + lastPageUrl: '/', + searchQuery: '', +}; + +// Actions +const TOGGLE_DARKMODE = 'TOGGLE_DARKMODE'; +const PUSH_NEW_PAGE = 'PUSH_NEW_PAGE'; +const PUSH_NEW_QUERY = 'PUSH_NEW_QUERY'; +export const toggleDarkMode = isDarkMode => ({ + type: TOGGLE_DARKMODE, + isDarkMode, +}); +export const pushNewPage = (pageTitle, pageUrl) => ({ + type: PUSH_NEW_PAGE, + pageTitle, + pageUrl, +}); +export const pushNewQuery = query => ({ + type: PUSH_NEW_QUERY, + query, +}); + +// Reducer +export default (state = initialState, action) => { + switch (action.type) { + case TOGGLE_DARKMODE: + return { + ...state, + isDarkMode: action.isDarkMode, + }; + case PUSH_NEW_PAGE: + return { + ...state, + lastPageTitle: action.pageTitle, + lastPageUrl: action.pageUrl, + }; + case PUSH_NEW_QUERY: + return { + ...state, + searchQuery: action.query, + }; + default: + return state; + } +}; diff --git a/src/docs/state/index.js b/src/docs/state/index.js new file mode 100644 index 000000000..1ee96d387 --- /dev/null +++ b/src/docs/state/index.js @@ -0,0 +1,4 @@ +import { combineReducers } from 'redux'; +import app from './app'; + +export default combineReducers({ app }); diff --git a/src/docs/styles/_button.scss b/src/docs/styles/_button.scss new file mode 100644 index 000000000..689b7e96d --- /dev/null +++ b/src/docs/styles/_button.scss @@ -0,0 +1,85 @@ +// =================================================== +// Buttons +// =================================================== +.button, a.button { + color: var(--button-fore-color); + font-weight: 500; + font-size: 1.125rem; + line-height: 1.4; + transition: 0.3s ease all; + padding: 0.625rem 0.875rem; + margin-top: 0.75rem; + border-radius: 1rem; + display: inline-block; + box-shadow: 0px 4px 8px var(--button-shadow-color); + border: none; + cursor: pointer; + &:hover, &:focus { + box-shadow: 0px 8px 16px var(--button-shadow-color); + text-decoration: none; + outline: none; + } + &.button-a { + background: var(--button-back-color-a); + } + &.button-b { + background: var(--button-back-color-b); + } + svg { + vertical-align: sub; + } + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1.375rem; + line-height: 1.35; + } +} + +// Home button (404 page) +.button.button-home { + @media screen and (min-width: $layout-large-breakpoint) { + margin-top: 1.375rem; + } +} + +// Copy and share buttons (snippet card) +.button.button-copy { + position: absolute; + top: -32px; + right: 24px; + padding: 0.5rem 0.625rem; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-clipboard' %3E%3Cpath d='M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2'%3E%3C/path%3E%3Crect x='8' y='2' width='8' height='4' rx='1' ry='1'%3E%3C/rect%3E%3C/svg%3E"); + background-repeat: no-repeat; + background-position: center; + width: 44px; + height: 44px; +} +.button.button-social-sh { + position: absolute; + top: -32px; + right: 80px; + padding: 0.5rem 0.625rem; +} + +// Show/hide examples button (snippet card) +.button.button-example-toggler { + position: relative; + margin: -2rem 0px -1rem 0px; + background: var(--pre-back-color); + border-radius: 0px 0px 0.125rem 0.125rem; + width: calc(100%); + text-align: left; + display: block; + font-size: 0.875rem; + line-height: 1.35; + text-transform: uppercase; + font-weight: 300; + color: var(--button-example-toggler-fore-color); + box-shadow: none; + font-family: 'Roboto Mono', Menlo, Consolas, monospace; + &:hover, &:focus { + box-shadow: none; + } + svg { + margin-right: 0.125rem; + } +} \ No newline at end of file diff --git a/src/docs/styles/_card.scss b/src/docs/styles/_card.scss new file mode 100644 index 000000000..0d6f2da1b --- /dev/null +++ b/src/docs/styles/_card.scss @@ -0,0 +1,150 @@ +// =================================================== +// Cards +// =================================================== +.card { + position: relative; + transition: all 0.3s ease; + margin: 1rem 1.25rem; + background: var(--card-back-color); + color: var(--card-fore-color); + box-shadow: 0px 0px 1px var(--card-shadow-color-a), 0px 6px 12px var(--card-shadow-color-b); + border-radius: 0.125rem; + padding: 1rem; + .card-title { + font-size: 1.125rem; + line-height: 1.375; + font-weight: 500; + margin: 0px 0px 0.125rem; + a, a:link, a:visited { + font-weight: 500; + transition: 0.3s ease all; + color: var(--card-fore-color); + } + } + .card-description { + margin: 0.125rem -0.5rem 0.125rem; + font-size: 0.875rem; + color: var(--card-fore-color-light); + line-height: 1.35; + font-weight: 500; + } + .card-bottom { + position: relative; + margin-left: -1rem; + margin-right: -1rem; + border-radius: 0.125rem; + border-top-left-radius: 22px; + } + .card-code { + position: relative; + margin: 1.5rem 0px -1rem 0px; + background: var(--pre-back-color); + width: calc(100% - 36px); + border-radius: 1.375rem 0px 0.125rem 0.125rem; + line-height: 1.15; + padding: 2.25rem 1.125rem 2.25rem; + } + .card-examples { + transition: all 0.3s ease; + position: relative; + margin: 0.5rem 0px -1rem 0px; + background: var(--pre-back-color); + width: calc(100% - 52px); + border-radius: 0px 0px 0.125rem 0.125rem; + line-height: 1.15; + padding: 0.5rem 1.125rem 2.25rem 2.125rem; + &::before { + display: block; + content: ''; + position: absolute; + left: 21px; + top: 0; + width: 1px; + opacity: 0.75; + height: calc(100% - 24px); + background: var(--button-example-toggler-fore-color); + } + } + &.short { + .card-bottom { + display: none; + @media screen and (min-width: $layout-large-breakpoint) { + display: block; + } + } + } + &:not(.short) { + background: linear-gradient(to bottom, var(--card-back-color) 0px, var(--card-back-color) calc(100% - 17px), var(--pre-back-color) calc(100% - 16px)); + } +} + +// Card expertise corners +.card-corner { + box-sizing: border-box; + position: absolute; + top: 24px; + right: 16px; + width: 0.5rem; + height: 0.5rem; + border-radius: 0.5rem; + background: var(--corner-color); + &.beginner { + --corner-color: var(--beginner-color); + } + &.intermediate { + --corner-color: var(--intermediate-color); + } + &.advanced { + --corner-color: var(--advanced-color); + } + &.intermediate, &.advanced { + &::before { + display: block; + position: absolute; + content: ''; + top: 0px; + right: 12px; + width: 0.5rem; + height: 0.5rem; + border-radius: 0.5rem; + background: var(--corner-color); + } + } + &.advanced { + &::after { + display: block; + position: absolute; + content: ''; + top: 0px; + right: 24px; + width: 0.5rem; + height: 0.5rem; + border-radius: 0.5rem; + background: var(--corner-color); + } + } +} + +// Tags +:not(.token).tag { + transition: 0.3s ease all; + border: 2px solid var(--tag-border-color); + border-radius: 0.25rem; + color: var(--tag-fore-color); + text-transform: uppercase; + margin: 0px 0.375rem 0.25rem 0px; + display: inline-block; + padding: 0.125rem 0.25rem; + letter-spacing: 0.25px; + font-size: 0.625rem; + line-height: 1.4; + font-weight: 500; + &:first-of-type { + margin-top: 0.375rem; + } +} + +// Animation for card example +.roll-up-height { + transition: height 0.3s ease-in-out; +} \ No newline at end of file diff --git a/src/docs/styles/_code.scss b/src/docs/styles/_code.scss new file mode 100644 index 000000000..2f4e12a26 --- /dev/null +++ b/src/docs/styles/_code.scss @@ -0,0 +1,125 @@ +// Style code +code, kbd, pre { + font-size: 0.875em; +} +code, kbd, pre, code *, pre *, kbd *, code[class*="language-"], pre[class*="language-"] { + font-family: 'Roboto Mono', Menlo, Consolas, monospace; +} + +code { + background: var(--code-back-color); + color: var(--code-fore-color); + padding: 0.125rem 0.375rem; + border-radius: 0.125rem; +} +pre { + overflow: auto; // Responsiveness + background: var(--pre-back-color); + color: var(--pre-fore-color); + padding: 0.375rem; + margin: 0.5rem; + border: 0; +} + +code[class*="language-"], pre[class*="language-"] { + color: var(--pre-fore-color); + + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.8; + + -moz-tab-size: 2; + -o-tab-size: 2; + tab-size: 2; + + -webkit-hypens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +pre[class*="language-"] { + padding: 1rem; + overflow: auto; + margin: 0.5rem 0; + white-space: pre-wrap; +} + +pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, +code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { + background: var(--pre-selected-color); +} + +pre[class*="language-"]::selection, pre[class*="language-"] ::selection, +code[class*="language-"]::selection, code[class*="language-"] ::selection { + background: var(--pre-selected-color); +} + +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; + white-space: normal; +} + +.namespace { + opacity: .7; +} + +.token { + &.comment, &.prolog, &.doctype, &.cdata { + color: var(--token-color-a); + } + &.punctuation { + color: var(--token-color-b); + } + &.property, &.tag, &.boolean, &.constant, &.symbol, &.deleted, &.function { + color: var(--token-color-c); + } + &.number, &.class-name { + color: var(--token-color-d); + } + &.selector, &.attr-name, &.string, &.char, &.builtin, &.inserted { + color: var(--token-color-e); + } + &.operator, &.entity, &.url, &.atrule, &.attr-value, &.keyword, &.interpolation-punctuation { + color: var(--token-color-f); + } + &.regex { + color: var(--token-color-g); + } + &.important, &.variable { + color: var(--token-color-h); + } + &.italic, &.comment { + font-style: italic; + } + &.important, &.bold { + font-weight: 500; + } + &.entity { + cursor: help; + } +} +.language-css .token.string, .style .token.string { + color: var(--token-color-f); +} + +p > code, a > code { + &, &[class*="language-"] { + color: var(--code-fore-color); + background: var(--code-back-color); + &::-moz-selection, & ::-moz-selection { + background: var(--code-selected-color); + } + &::selection, & ::selection { + background: var(--code-selected-color); + } + } +} + +.token .token { + background: transparent; +} \ No newline at end of file diff --git a/src/docs/styles/_colors.scss b/src/docs/styles/_colors.scss new file mode 100644 index 000000000..38ad0d519 --- /dev/null +++ b/src/docs/styles/_colors.scss @@ -0,0 +1,140 @@ +:root { + // Interface color palette + --back-color: #F5F6FA; + --back-color-dark: #D7DDF3; + --fore-color: #404454; + --fore-color-light: #575E7A; + --fore-color-lighter: #666E8F; + --fore-color-dark: #1F253D; + --fore-color-darker: #060709; + + // Scrollbar + --scrollbar-back-color: #D7DDF3; + --scrollbar-fore-color: #666E8F; + + // Menu color palette + --menu-back-color: #FFFFFF; + --menu-border-color: #E4E6EC; + --menu-fore-color: #53586A; + --menu-active-fore-color: #2747C7; + + // Card corner palette + --beginner-color: #7CB342; + --intermediate-color: #FFB300; + --advanced-color: #D66361; + + // Search color palette + --search-back-color: #FFFFFF; + --search-fore-color: #0D0E17; + --search-placeholder-color: #C5C6CD; + --search-shadow-color: rgba(0, 32, 128, 0.1); + --search-shadow-focus-color: rgba(0, 32, 128, 0.17); + + // Button color palette + --button-back-color-a: #3B3EFC; + --button-back-color-b: #DC325F; + --button-fore-color: #FFFFFF; + --button-shadow-color: rgba(0, 0, 0, 0.25); + --button-shadow-focus-color: rgba(0, 0, 0, 0.29); + --button-example-toggler-fore-color: #607d8b; + + // Card color palette + --card-back-color: #FFFFFF; + --card-fore-color: #212121; + --card-fore-color-light: #424242; + --card-shadow-color-a: rgba(240, 242, 247, 0.1); + --card-shadow-color-b: rgba(0, 32, 128, 0.1); + + // Pre & Code color palette + --pre-fore-color: #e57373; + --pre-back-color: #1e253d; + --pre-selected-color: #041248; + + // Token color palette + --token-color-a: #7f99a5; // Comments + --token-color-b: #bdbdbd; // Punctuation + --token-color-c: #64b5f6; // Functions + --token-color-d: #ff8f00; // Numbers + --token-color-e: #c5e1a5; // Strings + --token-color-f: #ce93d8; // Keywords + --token-color-g: #26c6da; // Regular expressions + --token-color-h: #e57373; // Variables + + // Tag color palette + --tag-border-color: #D7DDF3; + --tag-fore-color: #616B8F; + + // Toast color palette + --toast-back-color: #05A864; + --toast-fore-color: #FFFFFF; + --toast-shadow-color: rgba(0, 32, 128, 0.26); + + // Link color palette + --a-link-color: #0277bd; + --a-visited-color: #01579b; + + // Code color palette + --code-fore-color: #0324AB; + --code-back-color: #EDF0FC; + --code-selected-color: #BDEDFE; +} + +// Dark mode colors +.page-container.dark { + // Interface color palette + --back-color: #2A314C; + --back-color-dark: #8993BE; + --fore-color: #ABAFBF; + --fore-color-light: #858CA8; + --fore-color-lighter: #707899; + --fore-color-dark: #B4BCD9; + --fore-color-darker: #FCFCFD; + + // Scrollbar + --scrollbar-back-color: #434E76; + --scrollbar-fore-color: #707899; + + // Menu color palette + --menu-back-color: #434E76; + --menu-border-color: #13151B; + --menu-fore-color: #959AAC; + --menu-active-fore-color: #CDD4EF; + + // Card corner palette remains unchanged for consistency + + // Search color palette + --search-back-color: #434E76; + --search-fore-color: #E8E9F2; + --search-placeholder-color: #999EBD; + --search-shadow-color: rgba(1, 8, 30, 0.24); + --search-shadow-focus-color: rgba(1, 8, 30, 0.31); + + // Button color palette remains unchanged for consistency + + // Card color palette + --card-back-color: #434E76; + --card-fore-color: #F0F0F0; + --card-fore-color-light: #D6D6D6; // previously C0C0C0, careful + --card-shadow-color-b: rgba(1, 8, 30, 0.24); + + // Pre & Code color palette remains unchanged for consistency + + // Token color palette remains unchanged for consistency + + // Tag color palette + --tag-border-color: #2A3765; + --tag-fore-color: #BEC1CB; // previously 999DAD, careful + + // Toast color palette + --toast-shadow-color: rgba(1, 8, 30, 0.44); + + // Link color palette + --a-link-color: #6DC7FD; + --a-visited-color: #5DB7FE; + + // Code color palette + --code-fore-color: #d1dafe; + --code-back-color: #4f5fa0; + --code-selected-color: #0dbcfb; + +} \ No newline at end of file diff --git a/src/docs/styles/_fonts.scss b/src/docs/styles/_fonts.scss new file mode 100644 index 000000000..42e20aed6 --- /dev/null +++ b/src/docs/styles/_fonts.scss @@ -0,0 +1,89 @@ +// Load external fonts - progressive loading should help alleviate performance issues +@font-face { + font-family: 'Roboto Mono'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: local('Roboto Mono'), local('RobotoMono-Regular'), url(../../../assets/RobotoMono-Regular.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Roboto Mono'; + font-style: italic; + font-weight: 400; + font-display: swap; + src: local('Roboto Mono Italic'), local('RobotoMono-Italic'), url(../../../assets/RobotoMono-Italic.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Roboto Mono'; + font-style: normal; + font-weight: 500; + src: local('Roboto Mono Medium'), local('RobotoMono-Medium'), url(../../../assets/RobotoMono-Medium.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; + font-display: swap; +} +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 300; + font-display: swap; + src: local('Noto Sans Light'), local('NotoSans-Light'), url(../../../assets/NotoSans-Light.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: italic; + font-weight: 300; + font-display: swap; + src: local('Noto Sans LightItalic'), local('NotoSans-LightItalic'), url(../../../assets/NotoSans-LightItalic.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: local('Noto Sans'), local('NotoSans-Regular'), url(../../../assets/NotoSans-Regular.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: italic; + font-weight: 400; + font-display: swap; + src: local('Noto Sans Italic'), local('NotoSans-Italic'), url(../../../assets/NotoSans-Italic.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 500; + font-display: swap; + src: local('Noto Sans Medium'), local('NotoSans-Medium'), url(../../../assets/NotoSans-Medium.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: italic; + font-weight: 500; + font-display: swap; + src: local('Noto Sans Medium Italic'), local('NotoSans-MediumItalic'), url(../../../assets/NotoSans-MediumItalic.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 600; + font-display: swap; + src: local('Noto Sans SemiBold'), local('NotoSans-SemiBold'), url(../../../assets/NotoSans-SemiBold.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Noto Sans'; + font-style: italic; + font-weight: 600; + font-display: swap; + src: local('Noto Sans SemiBold Italic'), local('NotoSans-SemiBoldItalic'), url(../../../assets/NotoSans-SemiBoldItalic.ttf) format('truetype'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} \ No newline at end of file diff --git a/src/docs/styles/_layout.scss b/src/docs/styles/_layout.scss new file mode 100644 index 000000000..7057cd837 --- /dev/null +++ b/src/docs/styles/_layout.scss @@ -0,0 +1,340 @@ +// =================================================== +// Layout +// =================================================== +// Grid container +.page-container { + overflow: hidden; + transition: 0.3s ease all; + background: var(--back-color); + display: grid; + width: 100vw; + height: 100vh; + grid-template-areas: "content" "menu"; + grid-template-columns: 100%; + grid-template-rows: calc(100vh - 62px) 62px; + // Medium screen size (mobile landscape, tablet) + @media screen and (min-width: $layout-medium-breakpoint) { + grid-template-areas: "menu content"; + grid-template-columns: 62px calc(100vw - 62px); + grid-template-rows: 100%; + } + // Large screen size (desktop, laptop) + @media screen and (min-width: $layout-large-breakpoint) { + grid-template-areas: "menu . content ."; + grid-template-columns: 62px calc((100vw - 830px) / 2) 768px calc((100vw - 830px) / 2); + } +} +// Menu container +header.menu { + grid-area: menu; +} +// Content container +.content { + transition: 0.3s ease all; + grid-area: content; + overflow: auto; + background: var(--back-color); + &::-webkit-scrollbar-track { + background-color: var(--scrollbar-back-color); + margin: 0.5rem 0; + border-radius: 0.125rem; + } + &::-webkit-scrollbar { + width: 4px; + background: transparent; + } + &::-webkit-scrollbar-thumb { + background-color: var(--scrollbar-fore-color); + border: 1px solid var(--scrollbar-fore-color-lighter); + border-radius: 0.125rem; + } +} + +// Website title +h1.website-title { + transition: 0.3s ease all; + font-size: 0.875rem; + font-weight: 500; + color: var(--fore-color-lighter); + line-height: 1.5; + position: relative; + top: 4px; + margin: 1.5rem 1.25rem 0.125rem; + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1rem; + line-height: 1.375; + } +} +// Website logo +img.website-logo { + transition: 0.3s ease all; + position: absolute; + top: 8px; + right: 0px; + width: 48px; + height: 48px; +} +// Homepage logo +.index-logo { + transition: 0.3s ease all; + display: block; + margin: 1.5rem 1.25rem 0.5rem; + vertical-align: middle; + @media screen and (min-width: 144px) { + max-width: 128px; + margin: 1.5rem auto 0.5rem; + } + @media screen and (min-width: $layout-medium-breakpoint) { + display: inline-block; + margin: 1.5rem 2rem 0.5rem 1.25rem; + } +} +// Homepage title +.index-title { + transition: 0.3s ease all; + font-size: 2rem; + color: var(--fore-color-dark); + @media screen and (min-width: $layout-medium-breakpoint) { + display: inline-block; + } + margin: 0.75rem 1.25rem; + text-align: center; +} +// Homepage subtitle +.index-sub-title { + transition: 0.3s ease all; + font-size: 0.875rem; + line-height: 1.5; + margin: 1rem 1.25rem 1.25rem; + color: var(--fore-color); + text-align: center; + @media screen and (min-width: $layout-medium-breakpoint) { + font-size: 1rem; + } +} + +// Page title +.page-title { + font-size: 2.25rem; + font-weight: 400; + line-height: 1.36; + letter-spacing: 0.03em; + color: var(--fore-color-darker); + margin: 0 1.25rem; + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 2.5rem; + line-height: 1.35; + } +} +// Page subtitle +.page-sub-title { + transition: 0.3s ease all; + font-size: 1.125rem; + line-height: 1.35; + margin: 1rem 1.25rem 0.5rem; + color: var(--fore-color); + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1.25rem; + } +} +// Page light subtitle +p.light-sub { + transition: 0.3s ease all; + color: var(--fore-color-light); + font-size: 0.875rem; + line-height: 1.5; + margin: 0.125rem 1.25rem 0px; + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1rem; + line-height: 1.375; + } +} +// Category/tag title +.tag-title { + transition: 0.3s ease all; + font-size: 1.125rem; + color: var(-fore-color-dark); + line-height: 1.375; + a { + &, &:link, &:visited { + color: var(--fore-color-dark); + } + } + font-weight: 400; + cursor: pointer; + margin: 1.5rem 1.25rem 0.5rem; +} + +// Return to previous page link +a.link-back { + transition: 0.3s ease all; + font-size: 1.125rem; + line-height: 1.35; + display: block; + margin: 1rem 1.25rem 1.5rem; + font-weight: 500; + &, &:link, &:visited { + color: var(--fore-color-dark); + } + &:hover, &:focus { + text-decoration: none; + } + svg { + vertical-align: middle; + } +} + +// About page maintainers card +.flex-row { + display: flex; + flex: 0 1 auto; + flex-flow: row wrap; + .flex-item { + flex: 0 0 auto; + max-width: calc(50% - 24px); + flex-basis: calc(50% - 24px); + margin: 12px; + @media screen and (min-width: $layout-large-breakpoint) { + max-width: calc(25% - 24px); + flex-basis: calc(25% - 24px); + } + .media-section { + max-width: 100%; + height: auto; + border-radius: 0.5rem; + } + .button-section { + font-size: 0.875rem; + font-weight: 600; + text-align: center; + width: 100%; + display: block; + &, &:link, &:visited { + font-weight: 600; + color: var(--card-fore-color); + } + } + } +} + +// Page background graphic +.page-graphic { + position: relative; + box-sizing: border-box; + transition: all 0.3s ease; + margin-top: 100px; + width: 100%; + height: calc(50vmin); + &::before { + top: 0; + right: 27.5vmin; + position: absolute; + content: ''; + width: 45vmin; + height: 44vmin; + background-position-x: 52.5%, center; + background-position-y: 1%, top; + background-repeat: no-repeat; + background-size: 45vmin, 44vmin; + } + padding-top: 46vmin; + text-align: center; + @media screen and (orientation: landscape) and (max-height: calc(#{$layout-medium-breakpoint} - 1px)) { + margin-top: 2rem; + padding-top: 38vmin; + height: 40vmin; + &::before { + right: calc(50vw - 45vmin / 2 - 31px); + } + } + @media screen and (min-width: $layout-large-breakpoint) { + padding-top: 2vmin; + padding-right: 400px; + &::before { + background-size: 395px, 393px; + height: 400px; + width: 400px; + right: 1.125rem; + margin-top: -2vmin; + background-position-x: 95.5%, 93%; + } + } +} + +// Empty page text +.empty-page-text { + transition: color 0.3s ease, background 0.3s ease; + text-align: center; + margin: 2.25rem auto 0.75rem; + max-width: 200px; + font-size: 1rem; + line-height: 1.5; + color: var(--fore-color-darker); + font-weight: 400; + @media screen and (min-width: $layout-medium-breakpoint) { + max-width: 400px; + } + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1.75rem; + line-height: 1.35; + margin: 2.25rem auto 1.375rem 1.25rem; + &.search-page-text { + margin-top: 12vmin; + font-size: 1.375rem; + line-height: 1.375; + } + } +} +.empty-page-subtext { + transition: all 0.3s ease; + text-align: center; + font-size: 14px; + font-weight: 400; + line-height: 1.5; + max-width: 200px; + color: var(--fore-color-darker); + margin: 0.5rem auto; + @media screen and (min-width: $layout-medium-breakpoint) { + max-width: 256px; + } + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1.125rem; + line-height: 1.375; + } +} +// Background graphic styles and dark mode +.search-empty::before { + background-image: url("data:image/svg+xml,%3Csvg width='154' height='148' viewBox='0 0 154 148' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cline x1='72.7688' y1='68.1962' x2='88.5602' y2='83.9877' stroke='%23575E7A' stroke-width='2'/%3E%3Crect x='97.8234' y='75.055' width='76.9574' height='23.2664' rx='11.6332' transform='rotate(45 97.8234 75.055)' stroke='%23575E7A' stroke-width='2'/%3E%3Cpath d='M81.3085 50.7431C81.9744 47.8236 82.3261 44.7844 82.3261 41.6631C82.3261 35.0791 80.7613 28.8607 77.9834 23.3593' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M56.2702 3.70245C51.7367 1.95686 46.8116 1 41.663 1C19.2055 1 1 19.2055 1 41.663C1 64.1206 19.2055 82.3261 41.663 82.3261C59.2695 82.3261 74.2624 71.1364 79.9182 55.4806' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M62.1442 6.52702C65.6967 8.6023 68.9061 11.2009 71.6667 14.2172' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg width='152' height='150' viewBox='0 0 152 150' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M147.38 72.8499C153.437 95.1096 155.456 105.228 141.323 129.511C127.191 153.794 94.8556 149.747 72.6806 149.747C32.5402 149.747 0 117.131 0 76.8971C0 36.6632 34.5591 0 74.6995 0C114.84 0 141.323 50.5902 147.38 72.8499Z' fill='%23D7DDF3'/%3E%3C/svg%3E"); +} +.search-no-results::before { + background-image: url("data:image/svg+xml,%3Csvg width='154' height='148' viewBox='0 0 154 148' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cline x1='72.7688' y1='68.1962' x2='88.5602' y2='83.9877' stroke='%23575E7A' stroke-width='2'/%3E%3Crect x='97.8234' y='75.055' width='76.9574' height='23.2664' rx='11.6332' transform='rotate(45 97.8234 75.055)' stroke='%23575E7A' stroke-width='2'/%3E%3Cpath d='M81.3085 50.7432C81.9744 47.8236 82.3261 44.7844 82.3261 41.6631C82.3261 35.0792 80.7613 28.8607 77.9834 23.3593' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M56.2702 3.70245C51.7367 1.95686 46.8116 1 41.663 1C19.2055 1 1 19.2055 1 41.663C1 64.1206 19.2055 82.3261 41.663 82.3261C59.2695 82.3261 74.2624 71.1364 79.9182 55.4806' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M62.1442 6.52701C65.6967 8.60229 68.9061 11.2009 71.6667 14.2172' stroke='%23575E7A' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M11.3086 38.2034C11.3086 38.2034 13.5167 41.5575 16.9242 41.3193C20.3318 41.081 22.0516 37.4522 22.0516 37.4522M18.1449 58.7766C18.1449 58.7766 23.8094 54.872 31.061 54.3649C38.3125 53.8578 43.9281 56.9737 43.9281 56.9737M34.2526 36.599C34.2526 36.599 36.2089 39.9708 39.8682 39.7149C43.5276 39.459 44.9956 35.8478 44.9956 35.8478' stroke='%23575E7A' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A"), url("data:image/svg+xml,%3Csvg width='152' height='150' viewBox='0 0 152 150' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M147.38 72.8499C153.437 95.1096 155.456 105.228 141.323 129.511C127.191 153.794 94.8556 149.747 72.6806 149.747C32.5402 149.747 0 117.131 0 76.8971C0 36.6632 34.5591 0 74.6995 0C114.84 0 141.323 50.5902 147.38 72.8499Z' fill='%23D7DDF3'/%3E%3C/svg%3E"); +} +.page-not-found::before { + background-image: url("data:image/svg+xml,%3Csvg width='160' height='109' viewBox='0 0 160 109' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 7.99999C1 4.134 4.13401 1 8 1H95.1429H152C155.866 1 159 4.13401 159 8V100.571C159 104.437 155.866 107.571 152 107.571H8C4.13401 107.571 1 104.437 1 100.571V7.99999Z' stroke='%23575E7A' stroke-width='2'/%3E%3Cline x1='1' y1='17.8571' x2='83.5714' y2='17.8571' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='100.429' y1='17.8571' x2='116.714' y2='17.8571' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='128.429' y1='17.8571' x2='159' y2='17.8571' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='8.57138' cy='9.7142' r='1.85714' stroke='%23575E7A' stroke-width='2'/%3E%3Ccircle cx='17.7142' cy='9.7142' r='1.85714' stroke='%23575E7A' stroke-width='2'/%3E%3Ccircle cx='26.8573' cy='9.7142' r='1.85714' stroke='%23575E7A' stroke-width='2'/%3E%3Cline x1='33.9856' y1='38.2856' x2='41.4608' y2='45.7608' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='34.4762' y1='45.761' x2='41.9513' y2='38.2858' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='105.414' y1='38.2856' x2='112.889' y2='45.7608' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='105.905' y1='45.761' x2='113.38' y2='38.2858' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M49.8545 69.0772C49.8545 69.0772 57.5257 73.6485 72.1402 73.6485C86.7117 73.6485 94.4259 69.0771 94.4259 69.0771' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M72.1526 78.5698C72.3093 86.3002 68.3437 92.6498 63.2953 92.7521C58.2469 92.8544 54.0273 86.6706 53.8707 78.9402C53.8129 76.0901 54.3155 73.4277 55.2261 71.1969' stroke='%23575E7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M64.6687 73.7268C64.8334 73.1997 64.5396 72.6388 64.0125 72.4741C63.4853 72.3093 62.9245 72.6031 62.7597 73.1303L64.6687 73.7268ZM61.8707 88.7359C61.9615 89.2807 62.4768 89.6487 63.0215 89.5579C63.5663 89.4671 63.9343 88.9519 63.8435 88.4071L61.8707 88.7359ZM62.7597 73.1303C61.2791 77.8683 60.9909 83.4569 61.8707 88.7359L63.8435 88.4071C63.009 83.4002 63.2922 78.1317 64.6687 73.7268L62.7597 73.1303Z' fill='%23575E7A'/%3E%3C/svg%3E%0A"), url("data:image/svg+xml,%3Csvg width='172' height='170' viewBox='0 0 172 170' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M85.7456 16.9208C110.886 -6.48267 132.959 -4.28052 156.498 15.4794C180.037 35.2393 174.047 84.4687 153.005 119.028C128.204 159.761 84.2197 174.845 40.8539 167.344C-2.51188 159.842 -6.55002 107.678 7.88005 65.9713C22.3101 24.2642 60.6055 40.3243 85.7456 16.9208Z' fill='%23D7DDF3'/%3E%3C/svg%3E%0A"); + background-position-x: 53.5%, center; + background-position-y: 8.5%, top; + background-size: 41vmin, 44vmin; + &::before { + background-size: 395px, 393px; + height: 400px; + width: 400px; + right: 1.125rem; + margin-top: -15vmin; + background-position-x: 95.5%, 93%; + } + @media screen and (min-width: $layout-large-breakpoint) { + background-size: 367px, 393px; + background-position-x: 96.5%, 93%; + } +} +.page-container.dark { + .search-empty::before { + background-image: url("data:image/svg+xml,%3Csvg width='154' height='148' viewBox='0 0 154 148' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cline x1='72.7688' y1='68.1962' x2='88.5602' y2='83.9877' stroke='%238993BE' stroke-width='2'/%3E%3Crect x='97.8234' y='75.055' width='76.9574' height='23.2664' rx='11.6332' transform='rotate(45 97.8234 75.055)' stroke='%238993BE' stroke-width='2'/%3E%3Cpath d='M81.3085 50.7431C81.9744 47.8236 82.3261 44.7844 82.3261 41.6631C82.3261 35.0791 80.7613 28.8607 77.9834 23.3593' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M56.2702 3.70245C51.7367 1.95686 46.8116 1 41.663 1C19.2055 1 1 19.2055 1 41.663C1 64.1206 19.2055 82.3261 41.663 82.3261C59.2695 82.3261 74.2624 71.1364 79.9182 55.4806' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M62.1442 6.52702C65.6967 8.6023 68.9061 11.2009 71.6667 14.2172' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg width='152' height='150' viewBox='0 0 152 150' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M147.38 72.8499C153.437 95.1096 155.456 105.228 141.323 129.511C127.191 153.794 94.8556 149.747 72.6806 149.747C32.5402 149.747 0 117.131 0 76.8971C0 36.6632 34.5591 0 74.6995 0C114.84 0 141.323 50.5902 147.38 72.8499Z' fill='%23555C7C'/%3E%3C/svg%3E"); + } + .search-no-results::before { + background-image: url("data:image/svg+xml,%3Csvg width='154' height='148' viewBox='0 0 154 148' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cline x1='72.7688' y1='68.1962' x2='88.5602' y2='83.9877' stroke='%238993BE' stroke-width='2'/%3E%3Crect x='97.8234' y='75.055' width='76.9574' height='23.2664' rx='11.6332' transform='rotate(45 97.8234 75.055)' stroke='%238993BE' stroke-width='2'/%3E%3Cpath d='M81.3085 50.7432C81.9744 47.8236 82.3261 44.7844 82.3261 41.6631C82.3261 35.0792 80.7613 28.8607 77.9834 23.3593' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M56.2702 3.70245C51.7367 1.95686 46.8116 1 41.663 1C19.2055 1 1 19.2055 1 41.663C1 64.1206 19.2055 82.3261 41.663 82.3261C59.2695 82.3261 74.2624 71.1364 79.9182 55.4806' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M62.1442 6.52701C65.6967 8.60229 68.9061 11.2009 71.6667 14.2172' stroke='%238993BE' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M11.3086 38.2034C11.3086 38.2034 13.5167 41.5575 16.9242 41.3193C20.3318 41.081 22.0516 37.4522 22.0516 37.4522M18.1449 58.7766C18.1449 58.7766 23.8094 54.872 31.061 54.3649C38.3125 53.8578 43.9281 56.9737 43.9281 56.9737M34.2526 36.599C34.2526 36.599 36.2089 39.9708 39.8682 39.7149C43.5276 39.459 44.9956 35.8478 44.9956 35.8478' stroke='%238993BE' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A"), url("data:image/svg+xml,%3Csvg width='152' height='150' viewBox='0 0 152 150' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M147.38 72.8499C153.437 95.1096 155.456 105.228 141.323 129.511C127.191 153.794 94.8556 149.747 72.6806 149.747C32.5402 149.747 0 117.131 0 76.8971C0 36.6632 34.5591 0 74.6995 0C114.84 0 141.323 50.5902 147.38 72.8499Z' fill='%23555C7C'/%3E%3C/svg%3E"); + } + .page-not-found::before { + background-image: url("data:image/svg+xml,%3Csvg width='160' height='109' viewBox='0 0 160 109' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 7.99999C1 4.134 4.13401 1 8 1H95.1429H152C155.866 1 159 4.13401 159 8V100.571C159 104.437 155.866 107.571 152 107.571H8C4.13401 107.571 1 104.437 1 100.571V7.99999Z' stroke='%238993BE' stroke-width='2'/%3E%3Cline x1='1' y1='17.8571' x2='83.5714' y2='17.8571' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='100.429' y1='17.8571' x2='116.714' y2='17.8571' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='128.429' y1='17.8571' x2='159' y2='17.8571' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='8.57138' cy='9.7142' r='1.85714' stroke='%238993BE' stroke-width='2'/%3E%3Ccircle cx='17.7142' cy='9.7142' r='1.85714' stroke='%238993BE' stroke-width='2'/%3E%3Ccircle cx='26.8573' cy='9.7142' r='1.85714' stroke='%238993BE' stroke-width='2'/%3E%3Cline x1='33.9856' y1='38.2856' x2='41.4608' y2='45.7608' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='34.4762' y1='45.761' x2='41.9513' y2='38.2858' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='105.414' y1='38.2856' x2='112.889' y2='45.7608' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cline x1='105.905' y1='45.761' x2='113.38' y2='38.2858' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M49.8545 69.0772C49.8545 69.0772 57.5257 73.6485 72.1402 73.6485C86.7117 73.6485 94.4259 69.0771 94.4259 69.0771' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M72.1526 78.5698C72.3093 86.3002 68.3437 92.6498 63.2953 92.7521C58.2469 92.8544 54.0273 86.6706 53.8707 78.9402C53.8129 76.0901 54.3155 73.4277 55.2261 71.1969' stroke='%238993BE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M64.6687 73.7268C64.8334 73.1997 64.5396 72.6388 64.0125 72.4741C63.4853 72.3093 62.9245 72.6031 62.7597 73.1303L64.6687 73.7268ZM61.8707 88.7359C61.9615 89.2807 62.4768 89.6487 63.0215 89.5579C63.5663 89.4671 63.9343 88.9519 63.8435 88.4071L61.8707 88.7359ZM62.7597 73.1303C61.2791 77.8683 60.9909 83.4569 61.8707 88.7359L63.8435 88.4071C63.009 83.4002 63.2922 78.1317 64.6687 73.7268L62.7597 73.1303Z' fill='%238993BE'/%3E%3C/svg%3E%0A"), url("data:image/svg+xml,%3Csvg width='172' height='170' viewBox='0 0 172 170' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M85.7456 16.9208C110.886 -6.48267 132.959 -4.28052 156.498 15.4794C180.037 35.2393 174.047 84.4687 153.005 119.028C128.204 159.761 84.2197 174.845 40.8539 167.344C-2.51188 159.842 -6.55002 107.678 7.88005 65.9713C22.3101 24.2642 60.6055 40.3243 85.7456 16.9208Z' fill='%23555C7C'/%3E%3C/svg%3E%0A"); + } +} diff --git a/src/docs/styles/_menu.scss b/src/docs/styles/_menu.scss new file mode 100644 index 000000000..331b72bb7 --- /dev/null +++ b/src/docs/styles/_menu.scss @@ -0,0 +1,85 @@ +// =================================================== +// Menu +// =================================================== +.menu { + // z-index: 8; + transition: 0.3s ease all; + // Menu container + background: var(--menu-back-color); + border-top: 1px solid var(--menu-border-color); + @media screen and (max-width: calc(#{$layout-medium-breakpoint} - 1px)) { + position: fixed; + bottom: 0; + width: 100vw; + z-index: 1001; + } + @media screen and (min-width: $layout-medium-breakpoint) { + border-top: none; + border-right: 1px solid var(--menu-border-color); + padding-top: 17vh; + } + @media screen and (min-width: $layout-large-breakpoint) { + padding-top: 23.5vh; + } + // Menu buttons + .menu-button { + cursor: pointer; + transition: 0.3s ease all; + background: transparent; + color: var(--menu-fore-color); + display: inline-block; + width: 25%; + height: 61px; + margin: 0; + text-align: center; + margin-top: 0.5rem; + border: none; + line-height: 61px; + @media screen and (min-width: $layout-medium-breakpoint) { + height: 12.5vh; + width: 100%; + margin-top: 1vh; + margin-bottom: 4vh; + line-height: 12.5vh; + } + @media screen and (min-width: $layout-large-breakpoint) { + margin-bottom: 1vh; + } + &:hover, &:focus { + outline: 0; + color: var(--menu-active-fore-color); + } + &.active { + color: var(--menu-active-fore-color); + svg { + color: var(--menu-active-fore-color); + } + } + svg { + color: var(--menu-fore-color); + } + &:last-of-type { + vertical-align: top; + } + } +} + +// Animate transition between light and dark mode +.cross-fade-leave { + transform: scale(1); +} +.cross-fade-leave.cross-fade-leave-active { + transition: all 0.3s cubic-bezier(0.47, 0, 0.745, 0.715); + transform: scale(0.1); +} +.cross-fade-enter { + transform: scale(0.1); +} +.cross-fade-enter.cross-fade-enter-active { + transition: all 0.3s cubic-bezier(0.215, 0.610, 0.355, 1); + transform: scale(0.95) +} +.cross-fade-height { + height: 61px; + transition: height 0.15s ease-in-out 0.15s; +} \ No newline at end of file diff --git a/src/docs/styles/_reset.scss b/src/docs/styles/_reset.scss new file mode 100644 index 000000000..e4744fb45 --- /dev/null +++ b/src/docs/styles/_reset.scss @@ -0,0 +1,135 @@ +// Set up some basic styling for everything +html { + font-size: 16px; + scroll-behavior: smooth; +} +html, * { + font-family: 'Noto Sans', Helvetica, sans-serif; + line-height: 1.5; + // Prevent adjustments of font size after orientation changes in mobile. + -webkit-text-size-adjust: 100%; +} +* { + font-size: 1rem; + font-weight: 400; +} +// Apply fixes and defaults as necessary for modern browsers only +a, b, del, em, i, ins, q, span, strong, u { + transition: 0.3s ease all; + font-size: 1em; // Fix for elements inside headings not displaying properly. +} +body { + margin: 0; + color: var(--fore-color); + background: var(--background-color); + overflow-x: hidden; + &.card-page { + background: var(--card-page-color); + } +} +// Correct display for Edge & Firefox. +details { + display: block; +} +// Correct display in all browsers. +summary { + display: list-item; +} +// Abbreviations +abbr[title] { + border-bottom: none; // Remove bottom border in Firefox 39-. + text-decoration: underline dotted; // Opinionated style-fix for all browsers. +} +// Show overflow in Edge. +input { + overflow: visible; +} +// Correct the cursor style of increment and decrement buttons in Chrome. +[type="number"]::-webkit-inner-spin-button, [type="number"]::-webkit-outer-spin-button { + height: auto; +} +// Correct style in Chrome and Safari. +[type="search"] { + -webkit-appearance: textfield; + outline-offset: -2px; +} +// Correct style in Chrome and Safari. +[type="search"]::-webkit-search-cancel-button, [type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} +// Make images responsive by default. +img { + max-width: 100%; + height: auto; +} +// Style headings according to material design guidelines +h1, h2, h3, h4, h5, h6 { + line-height: 1.2; + margin: 0.75rem 0.5rem; +} +h1 { + font-size: 6rem; + &.landing-title { + font-size: 3rem; + text-align: center; + & small { + display: block; + margin-top: 0.5rem; + color: var(--secondary-fore-color); + } + margin-bottom: 4rem; + } +} +h2 { + font-size: 3.75rem; +} +h3 { + font-size: 3rem; +} +h4 { + font-size: 2.125rem; +} +h5 { + font-size: 1.5rem; +} +h6 { + font-size: 1.25rem; +} +// Style textual elements +p { + margin: 0.5rem; +} +ol, ul { + margin: 0.5rem; + padding-left: 1rem; +} +b, strong { + font-weight: 600; +} +hr { + // Fixes and defaults for styling + box-sizing: content-box; + border: 0; + // Actual styling using variables + line-height: 1.25em; + margin: 0.5rem; + height: 1px; + background: linear-gradient(to right, transparent, var(--border-color) 20%, var(--border-color) 80%, transparent); +} +sup, sub, code, kbd { + line-height: 0; + position: relative; + vertical-align: baseline; +} +a { + text-decoration: none; + &:link{ + color: var(--a-link-color); + } + &:visited { + color: var(--a-visited-color); + } + &:hover, &:focus { + text-decoration: underline; + } +} diff --git a/src/docs/styles/_search.scss b/src/docs/styles/_search.scss new file mode 100644 index 000000000..ccdae2fb7 --- /dev/null +++ b/src/docs/styles/_search.scss @@ -0,0 +1,57 @@ +// =================================================== +// Search +// =================================================== +[type="search"].search-box { + transition: 0.3s ease all; + margin: 0.25rem 0.875rem; + width: calc(100% - 1.75rem); + background: var(--search-back-color); + box-shadow: 0px 4px 8px var(--search-shadow-color); + &:focus { + box-shadow: 0px 6px 12px var(--search-shadow-focus-color); + } + border-radius: 1.125rem; + outline: none; + box-sizing: border-box; + border: none; + padding-left: 2.5rem; + font-size: 1.125rem; + font-weight: 300; + line-height: 2; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23C5C6CD' stroke-width='1.5' stroke-linecap='round' strokelinejoin='round' className='feather feather-search'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E"); + background-repeat: no-repeat; + background-position-x: 10px; + background-position-y: 8px; + color: var(--search-fore-color); + &::placeholder { + color: var(--search-placeholder-color); + } + @media screen and (min-width: $layout-large-breakpoint) { + font-size: 1.375rem; + line-height: 1.8; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23C5C6CD' stroke-width='1.5' stroke-linecap='round' strokelinejoin='round' className='feather feather-search'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E"); + } +} +// Dark mode +.page-container.dark [type="search"].search-box { + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23999EBD' stroke-width='1.5' stroke-linecap='round' strokelinejoin='round' className='feather feather-search'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E"); + @media screen and (min-width: $layout-large-breakpoint) { + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23999EBD' stroke-width='1.5' stroke-linecap='round' strokelinejoin='round' className='feather feather-search'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E"); + } +} + +.search-box::-webkit-input-placeholder { + font-family: 'Noto Sans', Helvetica, sans-serif; +} + +.search-box:-ms-input-placeholder { + font-family: 'Noto Sans', Helvetica, sans-serif; +} + +.search-box:-moz-placeholder { + font-family: 'Noto Sans', Helvetica, sans-serif; +} + +.search-box::-moz-placeholder { + font-family: 'Noto Sans', Helvetica, sans-serif; +} \ No newline at end of file diff --git a/src/docs/styles/_toast.scss b/src/docs/styles/_toast.scss new file mode 100644 index 000000000..ef1de925b --- /dev/null +++ b/src/docs/styles/_toast.scss @@ -0,0 +1,33 @@ +// =================================================== +// Toast +// =================================================== +.toast { + position: fixed; + bottom: 16px; + margin-bottom: 0; + font-size: 0.75rem; + line-height: 1.5; + left: 50%; + transform: translate(-50%, -50%); + z-index: 1111; + color: var(--toast-fore-color); + background: var(--toast-back-color); + border-radius: 2rem; + padding: 0.375rem 1.375rem 0.375rem 2.75rem; + box-shadow: 0px 0.25rem 0.5rem var(--toast-shadow-color); + transition: all 0.3s ease; + // Toast icon + &::before { + position: absolute; + content: ''; + display: block; + top: 1px; + left: 1px; + height: 28px; + background: white; + width: 28px; + border-radius: 100%; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2305A864' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-check'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E"); + background-position: center; + } +} \ No newline at end of file diff --git a/src/docs/styles/index.scss b/src/docs/styles/index.scss new file mode 100644 index 000000000..5efbdc51e --- /dev/null +++ b/src/docs/styles/index.scss @@ -0,0 +1,14 @@ +// Layout breakpoints +$layout-medium-breakpoint: 600px; +$layout-large-breakpoint: 900px; + +@import 'fonts'; +@import 'colors'; +@import 'reset'; +@import 'layout'; +@import 'menu'; +@import 'search'; +@import 'button'; +@import 'card'; +@import 'code'; +@import 'toast'; diff --git a/src/docs/templates/SnippetPage.js b/src/docs/templates/SnippetPage.js new file mode 100644 index 000000000..cb02f2552 --- /dev/null +++ b/src/docs/templates/SnippetPage.js @@ -0,0 +1,109 @@ +import React from 'react'; +import { graphql } from 'gatsby'; +import { connect } from 'react-redux'; + +import Meta from '../components/Meta'; +import Shell from '../components/Shell'; +import SnippetCard from '../components/SnippetCard'; +import BackArrowIcon from '../components/SVGs/BackArrowIcon'; +import AniLink from 'gatsby-plugin-transition-link/AniLink'; + +// =================================================== +// Individual snippet page template +// =================================================== +const SnippetPage = props => { + const post = props.data.markdownRemark; + const postData = props.data.snippetDataJson.data.find( + v => v.title === post.frontmatter.title, + ); + + return ( + <> + + + + +   Back to {props.lastPageTitle} + + + + + ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(SnippetPage); + +export const pageQuery = graphql` + query BlogPostBySlug($slug: String!) { + logo: file(absolutePath: { regex: "/logo_reverse_md.png/" }) { + id + childImageSharp { + fixed(height: 45, width: 45) { + src + } + } + } + allMarkdownRemark { + edges { + node { + fields { + slug + } + fileAbsolutePath + frontmatter { + title + } + } + } + } + markdownRemark(fields: { slug: { eq: $slug } }) { + id + fields { + slug + } + excerpt(pruneLength: 160) + html + frontmatter { + title + } + } + snippetDataJson(meta: { type: { eq: "snippetArray" } }) { + data { + title + id + attributes { + text + codeBlocks { + html + css + js + scopedCss + } + tags + } + } + } + } +`; diff --git a/src/docs/templates/TagPage.js b/src/docs/templates/TagPage.js new file mode 100644 index 000000000..59c38ce64 --- /dev/null +++ b/src/docs/templates/TagPage.js @@ -0,0 +1,84 @@ +import React from 'react'; +import { graphql } from 'gatsby'; +import { connect } from 'react-redux'; +import { pushNewPage } from '../state/app'; + +import Meta from '../components/Meta'; +import Shell from '../components/Shell'; +import SnippetCard from '../components/SnippetCard'; + +import { capitalize, getRawCodeBlocks as getCodeBlocks } from '../util'; + +// =================================================== +// Individual snippet category/tag page +// =================================================== +const TagRoute = props => { + const posts = props.data.allMarkdownRemark.edges; + const tag = props.pageContext.tag; + + React.useEffect(() => { + props.dispatch(pushNewPage(capitalize(tag), props.path)); + }, []); + + return ( + <> + + +

{capitalize(tag)}

+

Click on a snippet's name to view its code.

+ {posts && + posts.map(({ node }) => ( + v.trim()), + id: node.fields.slug.slice(1), + }} + isDarkMode={props.isDarkMode} + /> + ))} +
+ + ); +}; + +export default connect( + state => ({ + isDarkMode: state.app.isDarkMode, + lastPageTitle: state.app.lastPageTitle, + lastPageUrl: state.app.lastPageUrl, + searchQuery: state.app.searchQuery, + }), + null, +)(TagRoute); + +export const tagPageQuery = graphql` + query TagPage($tagRegex: String) { + allMarkdownRemark( + limit: 1000 + sort: { fields: [frontmatter___title], order: ASC } + filter: { frontmatter: { tags: { regex: $tagRegex } } } + ) { + totalCount + edges { + node { + excerpt(pruneLength: 400) + id + html + rawMarkdownBody + fields { + slug + } + frontmatter { + title + tags + } + } + } + } + } +`; diff --git a/src/docs/util/index.js b/src/docs/util/index.js new file mode 100644 index 000000000..6ce5afaa9 --- /dev/null +++ b/src/docs/util/index.js @@ -0,0 +1,135 @@ +const config = require('../../../config'); + +// Capitalizes the first letter of a string +const capitalize = (str, lowerRest = false) => + str.slice(0, 1).toUpperCase() + + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1)); + +// Get the textual content in a gatsby page +const getTextualContent = (str, noExplain = false) => { + const regex = /([\s\S]*?)
{ + results.push(match); + }); + } + if(noExplain) + return results[1].slice(0, results[1].lastIndexOf('

')); + return results[1]; +}; + +// Gets the code blocks in a gatsby page +const getCodeBlocks = str => { + const regex = //g; + let results = []; + let m = null; + while ((m = regex.exec(str)) !== null) { + if (m.index === regex.lastIndex) regex.lastIndex += 1; + // eslint-disable-next-line + m.forEach((match, groupIndex) => { + results.push(match); + }); + } + const replacer = new RegExp( + `

([\\s\\S]*?)
`, + 'g', + ); + const secondReplacer = new RegExp( + `
([\\s\\S]*?)
`, + 'g', + ); + const optionalReplacer = new RegExp( + `
([\\s\\S]*?)
`, + 'g', + ); + results = results.map(v => + v + .replace(replacer, '$1') + .replace(secondReplacer, '$1') + .replace(optionalReplacer, '$1') + .trim() + ); + if (results.length > 2) + return { + html: results[0], + css: results[1], + js: results[2], + }; + return { + html: results[0], + css: results[1], + js: '', + }; +}; + +// Optimizes nodes in an HTML string +const optimizeNodes = (data, regexp, replacer) => { + let count = 0; + let output = data; + do { + output = output.replace(regexp, replacer); + count = 0; + while (regexp.exec(output) !== null) ++count; + } while (count > 0); + return output; +}; +const optimizeAllNodes = html => { + let output = html; + // Optimize punctuation nodes + output = optimizeNodes( + output, + /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, + (match, p1, p2, p3) => + `${p1}${p2}${p3}`, + ); + // Optimize operator nodes + output = optimizeNodes( + output, + /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, + (match, p1, p2, p3) => + `${p1}${p2}${p3}`, + ); + // Optimize keyword nodes + output = optimizeNodes( + output, + /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, + (match, p1, p2, p3) => `${p1}${p2}${p3}`, + ); + return output; +}; + +// Gets the code blocks for a snippet file. +const getRawCodeBlocks = str => { + const regex = /```[.\S\s]*?```/g; + let results = []; + let m = null; + while ((m = regex.exec(str)) !== null) { + if (m.index === regex.lastIndex) regex.lastIndex += 1; + // eslint-disable-next-line + m.forEach((match, groupIndex) => { + results.push(match); + }); + } + const replacer = new RegExp( + `\`\`\`${config.language}([\\s\\S]*?)\`\`\``, + 'g', + ); + results = results.map(v => v.replace(replacer, '$1').trim()); + return { + code: results[0], + example: results[1], + }; +}; + +module.exports = { + capitalize, + getTextualContent, + getCodeBlocks, + optimizeNodes, + optimizeAllNodes, + getRawCodeBlocks, +};