Skip to content

Commit 6eb08db

Browse files
authored
[PLAY-1501] Enable Lightweight User Names in User Kit (#4194)
**What does this PR do?** A clear and concise description with your runway ticket url. Allows user to set user names in `User` kit to lightweight. [Story 1501](https://runway.powerhrg.com/backlog_items/PLAY-1501) **Screenshots:** Screenshots to visualize your addition/change **Rails:** <img width="1050" alt="Screenshot 2025-01-29 at 3 33 00 PM" src="https://github.com/user-attachments/assets/a4beb309-254e-4bcf-8a23-1958e0eb108a" /> **React:** <img width="709" alt="Screenshot 2025-01-29 at 3 33 53 PM" src="https://github.com/user-attachments/assets/3599805d-774f-4653-8c0c-12cdca10a413" /> **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [x] **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. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [x] **TESTS** I have added test coverage to my code.
1 parent 930c2f2 commit 6eb08db

File tree

9 files changed

+125
-1
lines changed

9 files changed

+125
-1
lines changed

playbook/app/pb_kits/playbook/pb_user/_user.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type UserProps = {
1313
aria?: {[key: string]: string},
1414
avatar?: boolean,
1515
avatarUrl?: string,
16+
bold?: boolean,
1617
className?: string,
1718
dark?: boolean,
1819
data?: {[key: string]: string},
@@ -32,6 +33,7 @@ const User = (props: UserProps): React.ReactElement => {
3233
aria = {},
3334
avatar = false,
3435
avatarUrl,
36+
bold = true,
3537
className,
3638
dark = false,
3739
data = {},
@@ -75,6 +77,7 @@ const User = (props: UserProps): React.ReactElement => {
7577
}
7678
<div className="content_wrapper">
7779
<Title
80+
bold={bold}
7881
dark={dark}
7982
size={size == 'lg' ? 3 : 4}
8083
text={name}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="pb--doc-demo-row">
2+
<div>
3+
<%= pb_rails("user", props: {
4+
name: "Anna Black",
5+
title: "Remodeling Consultant",
6+
orientation: "vertical",
7+
align: "center",
8+
size: "lg",
9+
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
10+
bold: false
11+
}) %>
12+
</div>
13+
<div>
14+
<%= pb_rails("user", props: {
15+
name: "Anna Black",
16+
title: "Remodeling Consultant",
17+
orientation: "horizontal",
18+
align: "left",
19+
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
20+
bold: false
21+
}) %>
22+
</div>
23+
<div>
24+
<%= pb_rails("user", props: {
25+
name: "Anna Black",
26+
orientation: "horizontal",
27+
align: "left",
28+
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
29+
bold: false
30+
}) %>
31+
32+
<br>
33+
34+
<%= pb_rails("user", props: {
35+
name: "Anna Black",
36+
orientation: "horizontal",
37+
align: "left",
38+
avatar: true,
39+
bold: false
40+
}) %>
41+
</div>
42+
</div>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react'
2+
import { User } from 'playbook-ui'
3+
4+
const UserLightWeight = (props) => {
5+
return (
6+
<div className="pb--doc-demo-row">
7+
8+
<div>
9+
<User
10+
align="center"
11+
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
12+
bold={false}
13+
name="Anna Black"
14+
orientation="vertical"
15+
size="lg"
16+
title="Remodeling Consultant"
17+
{...props}
18+
/>
19+
</div>
20+
21+
<div>
22+
<User
23+
align="left"
24+
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
25+
bold={false}
26+
name="Anna Black"
27+
orientation="horizontal"
28+
title="Remodeling Consultant"
29+
{...props}
30+
/>
31+
</div>
32+
33+
<div>
34+
<User
35+
align="left"
36+
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
37+
bold={false}
38+
name="Anna Black"
39+
orientation="horizontal"
40+
{...props}
41+
/>
42+
43+
<br />
44+
45+
<User
46+
align="left"
47+
avatar
48+
bold={false}
49+
name="Anna Black"
50+
orientation="horizontal"
51+
{...props}
52+
/>
53+
</div>
54+
55+
</div>
56+
)
57+
}
58+
59+
export default UserLightWeight
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
##### Prop
2+
Name will use `font-weight: 700` by default, if you want a lighter font weight, use the `bold` prop set to `false`. Name will then use `font-weight: 300`.

playbook/app/pb_kits/playbook/pb_user/docs/example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ examples:
22

33
rails:
44
- user_default: Default
5+
- user_light_weight: Light Weight
56
- user_with_territory: With Territory
67
- user_text_only: Text Only
78
- user_size: Horizontal Size
@@ -11,6 +12,7 @@ examples:
1112

1213
react:
1314
- user_default: Default
15+
- user_light_weight: Light Weight
1416
- user_with_territory: With Territory
1517
- user_text_only: Text Only
1618
- user_size: Horizontal Size

playbook/app/pb_kits/playbook/pb_user/docs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as UserDefault } from './_user_default.jsx'
2+
export { default as UserLightWeight } from './_user_light_weight.jsx'
23
export { default as UserWithTerritory } from './_user_with_territory.jsx'
34
export { default as UserTextOnly } from './_user_text_only.jsx'
45
export { default as UserSize } from './_user_size.jsx'

playbook/app/pb_kits/playbook/pb_user/user.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}) %>
1313
<% end %>
1414
<%= content_tag(:div, class: "content_wrapper") do %>
15-
<%= pb_rails("title", props: { text: object.name, size: object.title_size, dark: object.dark }) %>
15+
<%= pb_rails("title", props: { text: object.name, size: object.title_size, dark: object.dark, bold: object.bold }) %>
1616
<%= pb_rails("body", props: {
1717
text: "#{object.details}",
1818
dark: object.dark,

playbook/app/pb_kits/playbook/pb_user/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class User < Playbook::KitBase
99
prop :avatar, type: Playbook::Props::Boolean,
1010
default: false
1111
prop :avatar_url
12+
prop :bold, type: Playbook::Props::Boolean, default: true
1213
prop :name
1314
prop :orientation, type: Playbook::Props::Enum,
1415
values: %w[vertical horizontal],

playbook/app/pb_kits/playbook/pb_user/user.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ test('subtitle prop accepts a node', () => {
2626

2727
expect(screen.getByTestId('test-subtitle-block')).toHaveTextContent('test caption')
2828
})
29+
30+
test('bold prop applies correct styling when false', () => {
31+
render(
32+
<User
33+
bold={false}
34+
data={{ testid: 'test-bold-false' }}
35+
name="Anna Black"
36+
/>
37+
)
38+
const titleElement = screen.getByText("Anna Black")
39+
expect(titleElement).toBeInTheDocument()
40+
41+
expect(titleElement).toHaveClass('pb_title_kit_size_4_thin')
42+
})

0 commit comments

Comments
 (0)