Skip to content

Commit

Permalink
[PLAY-1501] Enable Lightweight User Names in User Kit (#4194)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
cmhorsey authored Jan 31, 2025
1 parent 930c2f2 commit 6eb08db
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 1 deletion.
3 changes: 3 additions & 0 deletions playbook/app/pb_kits/playbook/pb_user/_user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type UserProps = {
aria?: {[key: string]: string},
avatar?: boolean,
avatarUrl?: string,
bold?: boolean,
className?: string,
dark?: boolean,
data?: {[key: string]: string},
Expand All @@ -32,6 +33,7 @@ const User = (props: UserProps): React.ReactElement => {
aria = {},
avatar = false,
avatarUrl,
bold = true,
className,
dark = false,
data = {},
Expand Down Expand Up @@ -75,6 +77,7 @@ const User = (props: UserProps): React.ReactElement => {
}
<div className="content_wrapper">
<Title
bold={bold}
dark={dark}
size={size == 'lg' ? 3 : 4}
text={name}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="pb--doc-demo-row">
<div>
<%= pb_rails("user", props: {
name: "Anna Black",
title: "Remodeling Consultant",
orientation: "vertical",
align: "center",
size: "lg",
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
bold: false
}) %>
</div>
<div>
<%= pb_rails("user", props: {
name: "Anna Black",
title: "Remodeling Consultant",
orientation: "horizontal",
align: "left",
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
bold: false
}) %>
</div>
<div>
<%= pb_rails("user", props: {
name: "Anna Black",
orientation: "horizontal",
align: "left",
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
bold: false
}) %>

<br>

<%= pb_rails("user", props: {
name: "Anna Black",
orientation: "horizontal",
align: "left",
avatar: true,
bold: false
}) %>
</div>
</div>
59 changes: 59 additions & 0 deletions playbook/app/pb_kits/playbook/pb_user/docs/_user_light_weight.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react'
import { User } from 'playbook-ui'

const UserLightWeight = (props) => {
return (
<div className="pb--doc-demo-row">

<div>
<User
align="center"
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
bold={false}
name="Anna Black"
orientation="vertical"
size="lg"
title="Remodeling Consultant"
{...props}
/>
</div>

<div>
<User
align="left"
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
bold={false}
name="Anna Black"
orientation="horizontal"
title="Remodeling Consultant"
{...props}
/>
</div>

<div>
<User
align="left"
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
bold={false}
name="Anna Black"
orientation="horizontal"
{...props}
/>

<br />

<User
align="left"
avatar
bold={false}
name="Anna Black"
orientation="horizontal"
{...props}
/>
</div>

</div>
)
}

export default UserLightWeight
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
##### Prop
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`.
2 changes: 2 additions & 0 deletions playbook/app/pb_kits/playbook/pb_user/docs/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ examples:

rails:
- user_default: Default
- user_light_weight: Light Weight
- user_with_territory: With Territory
- user_text_only: Text Only
- user_size: Horizontal Size
Expand All @@ -11,6 +12,7 @@ examples:

react:
- user_default: Default
- user_light_weight: Light Weight
- user_with_territory: With Territory
- user_text_only: Text Only
- user_size: Horizontal Size
Expand Down
1 change: 1 addition & 0 deletions playbook/app/pb_kits/playbook/pb_user/docs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as UserDefault } from './_user_default.jsx'
export { default as UserLightWeight } from './_user_light_weight.jsx'
export { default as UserWithTerritory } from './_user_with_territory.jsx'
export { default as UserTextOnly } from './_user_text_only.jsx'
export { default as UserSize } from './_user_size.jsx'
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_user/user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}) %>
<% end %>
<%= content_tag(:div, class: "content_wrapper") do %>
<%= pb_rails("title", props: { text: object.name, size: object.title_size, dark: object.dark }) %>
<%= pb_rails("title", props: { text: object.name, size: object.title_size, dark: object.dark, bold: object.bold }) %>
<%= pb_rails("body", props: {
text: "#{object.details}",
dark: object.dark,
Expand Down
1 change: 1 addition & 0 deletions playbook/app/pb_kits/playbook/pb_user/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class User < Playbook::KitBase
prop :avatar, type: Playbook::Props::Boolean,
default: false
prop :avatar_url
prop :bold, type: Playbook::Props::Boolean, default: true
prop :name
prop :orientation, type: Playbook::Props::Enum,
values: %w[vertical horizontal],
Expand Down
14 changes: 14 additions & 0 deletions playbook/app/pb_kits/playbook/pb_user/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ test('subtitle prop accepts a node', () => {

expect(screen.getByTestId('test-subtitle-block')).toHaveTextContent('test caption')
})

test('bold prop applies correct styling when false', () => {
render(
<User
bold={false}
data={{ testid: 'test-bold-false' }}
name="Anna Black"
/>
)
const titleElement = screen.getByText("Anna Black")
expect(titleElement).toBeInTheDocument()

expect(titleElement).toHaveClass('pb_title_kit_size_4_thin')
})

0 comments on commit 6eb08db

Please sign in to comment.