Skip to content

Commit 9609963

Browse files
nidaqgElisaShapiro
andauthored
[PLAY-3163] New Kit: Container (#6546)
**What does this PR do?** A clear and concise description with your runway ticket url. [Runway Story](https://runway.powerhrg.com/backlog_items/PLAY-3163?from=active_sprint) New Container Kit **Screenshots:** Screenshots to visualize your addition/change **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [ ] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code. - [ ] **PLAYGROUND** I have added and tested Playground metadata and overrides for all kits and props updated in my code. - [ ] **SEMVER** I have added a `minor`, `major`, or `patch` label for release. - [ ] **RC** I have added an `inactive RC` label if not an active RC. --------- Co-authored-by: Elisa Shapiro <83474365+ElisaShapiro@users.noreply.github.com>
1 parent a41dbbb commit 9609963

25 files changed

Lines changed: 391 additions & 0 deletions

playbook-website/app/javascript/components/Website/src/pages/KitShow/playgroundEnabledKits.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const PLAYGROUND_ENABLED_KITS = [
1313
"circle_icon_button",
1414
"collapsible",
1515
"contact",
16+
"container",
1617
"copy_button",
1718
"currency",
1819
"dashboard_value",

playbook-website/config/menu.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,13 @@ kits:
647647
- category: layout_and_structure
648648
description: Components for structuring and organizing page layouts and content containers.
649649
components:
650+
- name: container
651+
platforms: *1
652+
description: The Container component is used as a wrapper for the content of a page or to any container.
653+
status: stable
654+
icons_used: false
655+
react_rendered: false
656+
enhanced_element_used: false
650657
- name: flex
651658
platforms: *1
652659
description: Flexbox layout helper for responsive rows, columns, spacing, and alignment in UIs.

playbook/app/entrypoints/playbook.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@import 'kits/pb_circle_icon_button/circle_icon_button';
1313
@import 'kits/pb_collapsible/collapsible';
1414
@import 'kits/pb_contact/contact';
15+
@import 'kits/pb_container/container';
1516
@import 'kits/pb_copy_button/copy_button';
1617
@import 'kits/pb_currency/currency';
1718
@import 'kits/pb_dashboard_value/dashboard_value';

playbook/app/javascript/kits.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { default as Checkbox } from '../pb_kits/playbook/pb_checkbox/_checkbox'
1616
export { default as CircleIconButton } from '../pb_kits/playbook/pb_circle_icon_button/_circle_icon_button'
1717
export { default as Collapsible } from '../pb_kits/playbook/pb_collapsible/_collapsible'
1818
export { default as Contact } from '../pb_kits/playbook/pb_contact/_contact'
19+
export { default as Container } from '../pb_kits/playbook/pb_container/_container'
1920
export { default as CopyButton} from '../pb_kits/playbook/pb_copy_button/_copy_button'
2021
export { default as Currency } from '../pb_kits/playbook/pb_currency/_currency'
2122
export { default as DashboardValue } from '../pb_kits/playbook/pb_dashboard_value/_dashboard_value'

playbook/app/javascript/playbook-doc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as Checkbox from '../pb_kits/playbook/pb_checkbox/docs'
1818
import * as CircleIconButton from '../pb_kits/playbook/pb_circle_icon_button/docs'
1919
import * as Collapsible from '../pb_kits/playbook/pb_collapsible/docs'
2020
import * as Contact from '../pb_kits/playbook/pb_contact/docs'
21+
import * as Container from '../pb_kits/playbook/pb_container/docs'
2122
import * as CopyButton from '../pb_kits/playbook/pb_copy_button/docs'
2223
import * as Currency from '../pb_kits/playbook/pb_currency/docs'
2324
import * as DashboardValue from '../pb_kits/playbook/pb_dashboard_value/docs'
@@ -127,6 +128,7 @@ ComponentRegistry.registerComponents({
127128
...CircleIconButton,
128129
...Collapsible,
129130
...Contact,
131+
...Container,
130132
...CopyButton,
131133
...Currency,
132134
...DashboardValue,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.pb_container_kit {
2+
3+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import classnames from 'classnames'
3+
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
4+
import { globalProps, GlobalProps } from '../utilities/globalProps'
5+
6+
type ContainerProps = {
7+
aria?: { [key: string]: string },
8+
children?: React.ReactNode,
9+
className?: string,
10+
data?: { [key: string]: string },
11+
htmlOptions?: { [key: string]: string | number | boolean | (() => void) | ((event: any) => void) | any },
12+
tag?: "div" | "span" | "a" | "button" | "option" | "table" | "tbody" | "thead" | "tfoot" | "tr" | "td" | "th" | "img" | "section" | "article" | "main" | "header" | "footer" | "nav" | "aside"
13+
id?: string,
14+
} & GlobalProps
15+
16+
const Container = (props: ContainerProps): React.ReactElement => {
17+
const {
18+
aria = {},
19+
children,
20+
className,
21+
data = {},
22+
htmlOptions = {},
23+
tag = 'div',
24+
id,
25+
} = props
26+
27+
const ariaProps = buildAriaProps(aria)
28+
const dataProps = buildDataProps(data)
29+
const htmlProps = buildHtmlProps(htmlOptions)
30+
const classes = classnames(buildCss('pb_container_kit'), globalProps(props), className)
31+
32+
const Tag = tag
33+
34+
return (
35+
<Tag
36+
{...ariaProps}
37+
{...dataProps}
38+
{...htmlProps}
39+
className={classes}
40+
id={id}
41+
>
42+
{children}
43+
</Tag>
44+
)
45+
}
46+
47+
export default Container
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%= pb_content_tag(object.tag) do %>
2+
<%= content.presence %>
3+
<% end %>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module Playbook
4+
module PbContainer
5+
class Container < ::Playbook::KitBase
6+
prop :tag, type: Playbook::Props::Enum,
7+
values: %w[div span a button option table tbody thead tfoot tr td th img section article main header footer nav aside],
8+
default: "div"
9+
10+
def classname
11+
generate_classname("pb_container_kit")
12+
end
13+
end
14+
end
15+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
import { render, screen } from '../utilities/test-utils'
3+
4+
import { Container } from 'playbook-ui'
5+
6+
/* See these resources for more testing info:
7+
- https://github.com/testing-library/jest-dom#usage for useage and examples
8+
- https://jestjs.io/docs/en/using-matchers
9+
*/
10+
11+
test('Container renders with default props', () => {
12+
const props = {
13+
children: 'Container Content'
14+
}
15+
16+
render(<Container {...props}>{props.children}</Container>)
17+
expect(screen.getByText(props.children)).toBeInTheDocument()
18+
})
19+
20+
test('Container renders with custom tag', () => {
21+
const props = {
22+
tag: 'span',
23+
children: 'Container Content'
24+
}
25+
26+
render(<Container {...props}>{props.children}</Container>)
27+
expect(screen.getByText(props.children)).toBeInTheDocument()
28+
})

0 commit comments

Comments
 (0)