diff --git a/contents/_includes/covers/accordion.njk b/contents/_includes/covers/accordion.njk new file mode 100644 index 0000000..e6c0ad8 --- /dev/null +++ b/contents/_includes/covers/accordion.njk @@ -0,0 +1,25 @@ +
+
+
+
+ {% triangle "r" %} +
+
+ {% rectangle %} +
+
+
+
+
+
+ {% triangle "b" %} +
+
+ {% rectangle %} +
+
+
+ {% lines "hor", 5 %} +
+
+
\ No newline at end of file diff --git a/contents/_includes/layouts/base.njk b/contents/_includes/layouts/base.njk index 5f87d72..a8225b9 100644 --- a/contents/_includes/layouts/base.njk +++ b/contents/_includes/layouts/base.njk @@ -7,14 +7,14 @@ - - + + - + - + diff --git a/contents/accordion.md b/contents/accordion.md new file mode 100644 index 0000000..0d1848b --- /dev/null +++ b/contents/accordion.md @@ -0,0 +1,87 @@ +--- +layout: layouts/post.njk +title: Accordion +description: Create an accordion with CSS flexbox +keywords: css accordion, css flexbox +--- + +{% include "covers/accordion.njk" %} + +## HTML + +```html + +
+ +
+ +
+ +
...
+ + +
+ ... +
+
+ + +
+ ... +
+
+ + +
+ ... +
+ + + ... +
+``` + +## CSS + +```css +.accordion { + /* Border */ + border: 1px solid rgba(0, 0, 0, 0.3); + border-bottom-color: transparent; + border-radius: 4px; +} + +.accordion__item { + border-bottom: 1px solid rgba(0, 0, 0, 0.3); +} + +.accordion__header { + /* Center the content horizontally */ + align-items: center; + display: flex; + + cursor: pointer; + padding: 16px; +} + +.accordion__toggle { + margin-right: 12px; +} + +.accordion__title { + /* Take remaining width */ + flex: 1; +} + +.accordion__content { + border-top: 1px solid rgba(0, 0, 0, 0.3); + padding: 16px; +} + +.accordion__item--collapsed .accordion__content { + display: none; +} +.accordion__item--expanded .accordion__content { + display: block; +} +``` \ No newline at end of file diff --git a/contents/index.njk b/contents/index.njk index 7f2e847..02153d9 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -10,20 +10,17 @@ eleventyExcludeFromCollections: true Star me on GitHub · {{ github.stargazers }}★ - {% for cat in collections.categories %} - {% set posts = collections.groupByCategories[cat] %}
-

{{ cat }}

+

Display

- {%- for post in posts | head(8) -%} - {%- endfor -%}
- See all {{ posts | length }} helpers
- {% endfor %} {% include "follow.njk" %} \ No newline at end of file diff --git a/pages/accordion/index.tsx b/pages/accordion/index.tsx deleted file mode 100644 index 7cce5b9..0000000 --- a/pages/accordion/index.tsx +++ /dev/null @@ -1,199 +0,0 @@ -import * as React from 'react'; -import Head from 'next/head'; -import { Spacer } from '@1milligram/design'; - -import { RelatedPatterns } from '../../components/RelatedPatterns'; -import { Pattern } from '../../constants/Pattern'; -import { PatternLayout } from '../../layouts/PatternLayout'; -import Block from '../../placeholders/Block'; -import BrowserFrame from '../../placeholders/BrowserFrame'; -import Rectangle from '../../placeholders/Rectangle'; -import Triangle from '../../placeholders/Triangle'; - -interface ItemProps { - index: number; - title: React.ReactNode; -} - -const Details: React.FC<{}> = () => { - const [activeItem, setActiveItem] = React.useState(1); - - const Item: React.FC = ({ index, title, children }) => { - const isOpened = index === activeItem; - const click = () => setActiveItem(isOpened ? -1 : index); - return ( - <> -
-
-
- -
-
{title}
-
-
- {children} -
-
- - ); - }; - - return ( - - - - - - - - -
- -
- -
- -
...
- - -
- ... -
-
- - -
- ... -
-
- - - ... -
-`} - css={` - .accordion { - /* Border */ - border: 1px solid rgba(0, 0, 0, 0.3); - border-bottom-color: transparent; - border-radius: 4px; - } - - .accordion__item { - border-bottom: 1px solid rgba(0, 0, 0, 0.3); - } - - .accordion__header { - /* Center the content horizontally */ - align-items: center; - display: flex; - - cursor: pointer; - padding: 16px; - } - - .accordion__toggle { - margin-right: 12px; - } - - .accordion__title { - /* Take remaining width */ - flex: 1; - } - - .accordion__content { - /* For not selected item */ - display: none; - - border-top: 1px solid rgba(0, 0, 0, 0.3); - padding: 16px; - } - - .accordion__content--selected { - /* For selected item */ - display: block; - } - `} - > -
-
- - -
- } - > -
- -
- - - -
- } - > -
- -
- - - - - } - > -
- -
-
- - -
- - - - -
- ); -}; - -export default Details; diff --git a/patterns/accordion/Cover.tsx b/patterns/accordion/Cover.tsx deleted file mode 100644 index a9f281f..0000000 --- a/patterns/accordion/Cover.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import * as React from 'react'; - -import Frame from '../../placeholders/Frame'; -import Line from '../../placeholders/Line'; -import Rectangle from '../../placeholders/Rectangle'; -import Triangle from '../../placeholders/Triangle'; - -const Cover: React.FC<{}> = () => { - return ( - -
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
- -
-
-
-
-
- -
-
- -
-
-
-
- - ); -}; - -export default Cover; diff --git a/styles/covers/_accordion.scss b/styles/covers/_accordion.scss new file mode 100644 index 0000000..ab999e2 --- /dev/null +++ b/styles/covers/_accordion.scss @@ -0,0 +1,32 @@ +.accordion { + border: 1px solid rgba(0, 0, 0, 0.3); + border-radius: 4px; + height: 100%; + width: 100%; +} +.accordion__item:not(:last-child) { + border-bottom: 1px solid rgba(0, 0, 0, 0.3); +} +.accordion__header { + align-items: center; + display: flex; + justify-content: center; + cursor: pointer; + padding: 0.5rem; +} +.accordion__toggle { + margin-right: 0.25rem; +} +.accordion__title { + flex: 1; +} +.accordion__content { + padding: 0.5rem; +} + +.accordion__item--collapsed .accordion__content { + display: none; +} +.accordion__item--expanded .accordion__content { + display: block; +} \ No newline at end of file