diff --git a/contents/_includes/covers/circular-navigation.njk b/contents/_includes/covers/circular-navigation.njk new file mode 100644 index 0000000..5bdf8a9 --- /dev/null +++ b/contents/_includes/covers/circular-navigation.njk @@ -0,0 +1,7 @@ +
+ {% for i in range(0, 6) -%} +
+
{{ i + 1 }}
+
+ {%- endfor %} +
\ No newline at end of file diff --git a/contents/circular-navigation.md b/contents/circular-navigation.md new file mode 100644 index 0000000..e01008c --- /dev/null +++ b/contents/circular-navigation.md @@ -0,0 +1,73 @@ +--- +layout: layouts/post.njk +title: Circular navigation +description: Create a circular navigation with CSS flexbox +keywords: css circular navigation, css flexbox +--- + +## HTML + +```html +
+ + ... + + +
+ +
+ ... +
+
+ + + ... +
+``` + +## CSS + +```css +.circular-navigation { + position: relative; +} + +.circular-navigation__circle { + /* Position */ + position: absolute; + top: 0; + + /* + 3rem is the distance from the item to the trigger element. + Replace 0deg with 60deg, 180deg, 240deg, 300deg for another item + in case you want to have a total of 6 menu items. + The formulation is 360 / numberOfItems * indexOfItem + */ + transform: rotate(0deg) translateX(-3rem); + + /* Must have the same size as the trigger element */ + height: 2rem; + width: 2rem; +} + +.circular-navigation__content { + /* + Rotate it to make it displayed vertically + Replace -0deg with -60deg, -180deg, -240deg, -300deg for another item + in case you want to have a total of 6 menu items. + The formulation is -(360 / numberOfItems * indexOfItem) + */ + transform: rotate(-0deg); + + /* Center the content */ + align-items: center; + display: flex; + justify-content: center; + + /* Take full size */ + height: 100%; + width: 100%; +} +``` + +{% demo %}{% include "covers/circular-navigation.njk" %}{% enddemo %} diff --git a/contents/index.njk b/contents/index.njk index ff8aefb..74e4140 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -126,6 +126,7 @@ eleventyExcludeFromCollections: true

Navigation

{% pattern "Breadcrumb" %}{% include "covers/breadcrumb.njk" %}{% endpattern %} + {% pattern "Circular navigation" %}{% include "covers/circular-navigation.njk" %}{% endpattern %}
diff --git a/pages/circular-navigation/index.tsx b/pages/circular-navigation/index.tsx deleted file mode 100644 index 0703484..0000000 --- a/pages/circular-navigation/index.tsx +++ /dev/null @@ -1,145 +0,0 @@ -import * as React from 'react'; -import Head from 'next/head'; - -import { Pattern } from '../../constants/Pattern'; -import { PatternLayout } from '../../layouts/PatternLayout'; -import BrowserFrame from '../../placeholders/BrowserFrame'; -import Square from '../../placeholders/Square'; - -interface CircularItemProps { - degree: number; -} - -const CircularItem: React.FC = ({ degree, children }) => { - return ( -
-
- {children} -
-
- ); -}; - -const Details: React.FC<{}> = () => { - const numItems = 6; - - return ( - - - - - - - - - - ... - - - - - - ... - -`} - css={` - .navigation { - position: relative; - } - - .navigation__circle { - /* Position */ - position: absolute; - top: 0; - - /* - 80px is the distance from the item to the trigger element. - Replace 0deg with 60deg, 180deg, 240deg, 300deg for another item - in case you want to have a total of 6 menu items. - The formulation is 360 / numberOfItems * indexOfItem - */ - transform: rotate(0deg) translateX(-80px); - - /* Must have the same size as the trigger element */ - height: 32px; - width: 32px; - } - - .navigation__content { - /* - Rotate it to make it displayed vertically - Replace -0deg with -60deg, -180deg, -240deg, -300deg for another item - in case you want to have a total of 6 menu items. - The formulation is -(360 / numberOfItems * indexOfItem) - */ - transform: rotate(-0deg); - - /* Center the content */ - align-items: center; - display: flex; - justify-content: center; - - /* Take full size */ - height: 100%; - width: 100%; - } - `} - > -
-
-
- -
- {Array(numItems) - .fill(0) - .map((_, i) => { - return ( - - {i + 1} - - ); - })} -
-
-
-
- ); -}; - -export default Details; diff --git a/patterns/circular-navigation/Cover.tsx b/patterns/circular-navigation/Cover.tsx deleted file mode 100644 index 6a7e7dd..0000000 --- a/patterns/circular-navigation/Cover.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import * as React from 'react'; - -import Frame from '../../placeholders/Frame'; - -const Cover: React.FC<{}> = () => { - return ( - -
-
-
-
-
-
-
-
-
-
-
- - ); -}; - -export default Cover; diff --git a/styles/index.scss b/styles/index.scss index bb893f5..c21bc79 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -22,6 +22,7 @@ @import './patterns/card'; @import './patterns/centering'; @import './patterns/chip'; +@import './patterns/circular-navigation'; @import './patterns/close-button'; @import './patterns/color-swatch'; @import './patterns/concave-corners'; diff --git a/styles/patterns/_circular-navigation.scss b/styles/patterns/_circular-navigation.scss new file mode 100644 index 0000000..e5d39f9 --- /dev/null +++ b/styles/patterns/_circular-navigation.scss @@ -0,0 +1,77 @@ +.circular-navigation { + position: relative; + + /* Demo */ + align-items: center; + display: flex; + justify-content: center; + + height: 8rem; + width: 8rem; +} + +.circular-navigation__circle { + /* Position */ + position: absolute; + top: 0; + + /* + 3rem is the distance from the item to the trigger element. + Replace 0deg with 60deg, 180deg, 240deg, 300deg for another item + in case you want to have a total of 6 menu items. + The formulation is 360 / numberOfItems * indexOfItem + */ + transform: rotate(var(--circular-navigation__circle-degree)) translateX(-3rem); + + /* Must have the same size as the trigger element */ + height: 2rem; + width: 2rem; + + /* Demo */ + background-color: #d1d5db; + border-radius: 9999px; +} + +.circular-navigation__content { + /* + Rotate it to make it displayed vertically + Replace -0deg with -60deg, -180deg, -240deg, -300deg for another item + in case you want to have a total of 6 menu items. + The formulation is -(360 / numberOfItems * indexOfItem) + */ + transform: rotate(var(--circular-navigation__content-degree)); + + /* Center the content */ + align-items: center; + display: flex; + justify-content: center; + + /* Take full size */ + height: 100%; + width: 100%; +} + +.circular-navigation__circle--1 { + --circular-navigation__circle-degree: 0deg; + --circular-navigation__content-degree: -0deg; +} +.circular-navigation__circle--2 { + --circular-navigation__circle-degree: 60deg; + --circular-navigation__content-degree: -60deg; +} +.circular-navigation__circle--3{ + --circular-navigation__circle-degree: 120deg; + --circular-navigation__content-degree: -120deg; +} +.circular-navigation__circle--4 { + --circular-navigation__circle-degree: 180deg; + --circular-navigation__content-degree: -180deg; +} +.circular-navigation__circle--5 { + --circular-navigation__circle-degree: 240deg; + --circular-navigation__content-degree: -240deg; +} +.circular-navigation__circle--6 { + --circular-navigation__circle-degree: 300deg; + --circular-navigation__content-degree: -300deg; +}