Skip to content

Commit db175e5

Browse files
[PLAY-1821] Home Address Casing (#4176)
**What does this PR do?** A clear and concise description with your runway ticket url. This PR updates the `state` prop to always display capitalized states. It also adds a new `preserve_case` or `preserveCase` prop that will either titleize the address line based on true/false. [Story](https://runway.powerhrg.com/backlog_items/PLAY-1821) **Screenshots:** Screenshots to visualize your addition/change ![Screenshot 2025-01-27 at 2 04 06 PM](https://github.com/user-attachments/assets/675b8839-df17-4ccc-bb5a-acde9874c469) **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. - [ ] **TESTS** I have added test coverage to my code.
1 parent 6eb08db commit db175e5

8 files changed

+60
-9
lines changed

playbook/app/pb_kits/playbook/pb_home_address_street/_home_address_street.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type HomeAddressStreetProps = {
1818
className?: string,
1919
data?: { [key: string]: string },
2020
dark?: boolean,
21+
preserveCase?: boolean,
2122
emphasis: "street" | "city" | "none",
2223
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
2324
homeId: string,
@@ -43,6 +44,7 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
4344
htmlOptions = {},
4445
homeId,
4546
homeUrl,
47+
preserveCase = false,
4648
target,
4749
newWindow,
4850
houseStyle,
@@ -77,6 +79,8 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
7779
return null
7880
}
7981

82+
const formatStreetAdr = (address: string): string => preserveCase ? address : titleize(address)
83+
8084
return (
8185
<div
8286
className={classes(className, dark)}
@@ -91,7 +95,7 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
9195
dark={dark}
9296
size={4}
9397
>
94-
{joinPresent([titleize(address), houseStyle], ' · ')}
98+
{joinPresent([formatStreetAdr(address), houseStyle], ' · ')}
9599
</Title>
96100
<Title
97101
className="pb_home_address_street_address"
@@ -101,14 +105,14 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
101105
{titleize(addressCont)}
102106
</Title>
103107
<Body color="light">
104-
{`${titleize(city)}, ${state} ${zipcode}`}
108+
{`${titleize(city)}, ${state.toUpperCase()} ${zipcode}`}
105109
</Body>
106110
</div>
107111
}
108112
{emphasis == 'city' &&
109113
<div>
110114
<Body color="light">
111-
{joinPresent([titleize(address), houseStyle], ' · ')}
115+
{joinPresent([formatStreetAdr(address), houseStyle], ' · ')}
112116
</Body>
113117
<Body color="light">{titleize(addressCont)}</Body>
114118
<div>
@@ -118,7 +122,7 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
118122
size={4}
119123
tag="span"
120124
>
121-
{`${titleize(city)}, ${state}`}
125+
{`${titleize(city)}, ${state.toUpperCase()}`}
122126
</Title>
123127
<Body
124128
color="light"
@@ -132,15 +136,15 @@ const HomeAddressStreet = (props: HomeAddressStreetProps): React.ReactElement =>
132136
{emphasis == 'none' &&
133137
<div>
134138
<Body dark={dark}>
135-
{joinPresent([titleize(address), houseStyle], ' · ')}
139+
{joinPresent([formatStreetAdr(address), houseStyle], ' · ')}
136140
</Body>
137-
<Body dark={dark}>{titleize(addressCont)}</Body>
141+
<Body dark={dark}>{formatStreetAdr(addressCont)}</Body>
138142
<div>
139143
<Body
140144
color="light"
141145
dark={dark}
142146
>
143-
{`${titleize(city)}, ${state} ${zipcode}`}
147+
{`${titleize(city)}, ${state.toUpperCase()} ${zipcode}`}
144148
</Body>
145149
</div>
146150
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= pb_rails("home_address_street", props: {
2+
address: "70 pRoSpEcT ave",
3+
address_cont: "Apt M18",
4+
city: "West Chester",
5+
home_id: 8250263,
6+
home_url: "https://powerhrg.com/",
7+
preserve_case: true,
8+
state: "pa",
9+
zipcode: "19382",
10+
territory: "PHL",
11+
}) %>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
3+
import HomeAddressStreet from '../_home_address_street'
4+
5+
const HomeAddressStreetFormatting = (props) => {
6+
return (
7+
<HomeAddressStreet
8+
address="70 pRoSpEcT ave"
9+
addressCont="Apt M18"
10+
city="West Chester"
11+
homeId="8250263"
12+
homeUrl="https://powerhrg.com/"
13+
preserveCase
14+
state="pa"
15+
territory="PHL"
16+
zipcode="19382"
17+
{...props}
18+
/>
19+
)
20+
}
21+
22+
export default HomeAddressStreetFormatting
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `state` prop will always capitalize the state name, even if the data entered is in lowercase. For example, when `state="pa"` is passed, it will be rendered as "PA". When you pass `preserve_case: true`, the street address will be rendered exactly as entered, without automatic title capitalization.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `state` prop will always capitalize the state name, even if the data entered is in lowercase. For example, when `state="pa"` is passed, it will be rendered as "PA". When you pass `preserveCase`, the street address will be rendered exactly as entered, without automatic title capitalization.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ examples:
55
- home_address_street_emphasis: Emphasis
66
- home_address_street_modified: Modified
77
- home_address_street_link: Link
8+
- home_address_street_formatting: Formatting
89

910
react:
1011
- home_address_street_default: Default
1112
- home_address_street_emphasis: Emphasis
1213
- home_address_street_modified: Modified
1314
- home_address_street_link: Link
15+
- home_address_street_formatting: Formatting
1416

1517
swift:
1618
- home_address_street_default_swift: Default

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as HomeAddressStreetDefault } from './_home_address_street_defa
22
export { default as HomeAddressStreetEmphasis } from './_home_address_street_emphasis.jsx'
33
export { default as HomeAddressStreetModified } from './_home_address_street_modified.jsx'
44
export { default as HomeAddressStreetLink } from './_home_address_street_link.jsx'
5+
export { default as HomeAddressStreetFormatting } from './_home_address_street_formatting.jsx'

playbook/app/pb_kits/playbook/pb_home_address_street/home_address_street.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class HomeAddressStreet < Playbook::KitBase
1818
prop :state
1919
prop :zipcode
2020
prop :territory
21+
prop :preserve_case, default: false
2122
prop :dark, type: Playbook::Props::Boolean, default: false
2223

2324
def classname
@@ -29,15 +30,15 @@ def city_state_zip
2930
end
3031

3132
def city_state
32-
[city&.titleize, state].join(", ")
33+
[city&.titleize, state&.upcase].join(", ")
3334
end
3435

3536
def zip
3637
zipcode.to_s
3738
end
3839

3940
def address_house_style
40-
[address&.titleize, house_style].join(separator)
41+
[format_street_address, house_style].join(separator)
4142
end
4243

4344
def address_house_style2
@@ -48,6 +49,14 @@ def separator
4849
house_style ? " \u00b7 " : ""
4950
end
5051

52+
def format_street_address
53+
preserve_case ? address : custom_titleize(address)
54+
end
55+
56+
def custom_titleize(str)
57+
str.split(" ").map(&:capitalize).join(" ")
58+
end
59+
5160
def city_emphasis_props
5261
{
5362
address_house_style: address_house_style,

0 commit comments

Comments
 (0)