[LUNA-3186]: Make marker prop optional in BpkPriceRange#4158
[LUNA-3186]: Make marker prop optional in BpkPriceRange#4158Vincent Liu (xiaogliu) merged 6 commits intomainfrom
Conversation
- Deprecate showPriceIndicator prop in favour of marker.type API - Add MARKER_DISPLAY_TYPES constant (BUBBLE and DOT) - Make marker prop optional to support usage without a marker - Update type definitions with MarkerDisplayType - Add migration guide documentation - Update tests to cover new optional marker behaviour - Update examples and stories to demonstrate new API This is the expand phase of an expand-migrate-contract migration. The showPriceIndicator prop is now deprecated but still functional to maintain backward compatibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
| */ | ||
| showPriceIndicator?: boolean; | ||
| marker: Marker; | ||
| marker?: MarkerPriceRangePosition; |
There was a problem hiding this comment.
Will an error occur on the client side if the type is not updated after the type has been changed?
There was a problem hiding this comment.
No 🙂 Previously, the only type exported was BpkPriceRangeProps, the Marker type was never directly exported. While consumers can use the Marker type, they can only ever access it via indexing through the marker property (e.g. BpkPriceRangeProps['marker']). As MarkerPriceRangePosition is a superset of the original Marker, and we're not changing the name of the marker property, if a consumer fetched the old type of Marker by indexing through marker, when updating to the new minor version of backpack, the index will now point to MarkerPriceRangePosition, and will compile without errors.
Even if the consumer defined a new type themselves representing a Marker, this could still be passed safely (as the new MarkerPriceRangePosition is a superset of the old Marker). Testing this locally shows no errors 🙂
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Visit https://backpack.github.io/storybook-prs/4158 to see this build running in a browser. |
| } from './src/BpkPriceRange'; | ||
|
|
||
| export type { BpkPriceRangeProps }; | ||
| export default BpkPriceRange; |
| const defaultMarkerType = showPriceIndicator ?? true ? MARKER_DISPLAY_TYPES.BUBBLE : MARKER_DISPLAY_TYPES.DOT; | ||
| const markerType = marker?.type || defaultMarkerType; | ||
| const shouldShowMarker = !!marker; | ||
| const shouldShowBubble = shouldShowMarker && markerType === MARKER_DISPLAY_TYPES.BUBBLE; | ||
| const shouldShowDot = shouldShowMarker && markerType === MARKER_DISPLAY_TYPES.DOT; |
There was a problem hiding this comment.
If marker.type is set, use it. Otherwise, default to bubble unless showPriceIndicator is explicitly false, in which case show a dot.
Details
All of the below logic formulas evaluate to `true`.Here's a ChatGPT summary of the below
->: implication=: equality&: conjunction (and)
- (marker.type = bubble & showPriceIndicator = undefined) -> (shouldShowBubble = true) & (shouldShowDot = false)
- (marker.type = bubble & showPriceIndicator = true) -> (shouldShowBubble = true) & (shouldShowDot = false)
- (marker.type = bubble & showPriceIndicator = false) -> (shouldShowBubble = true) & (shouldShowDot = false)
- ((marker.type = dot & showPriceIndicator = undefined) -> (shouldShowBubble = false) & (shouldShowDot = true)
- ((marker.type = dot & showPriceIndicator = true) -> (shouldShowBubble = false) & (shouldShowDot = true)
- ((marker.type = dot & showPriceIndicator = false) -> (shouldShowBubble = false) & (shouldShowDot = true)
- ((marker.type = undefined & showPriceIndicator = undefined) -> (shouldShowBubble = true) & (shouldShowDot = false)
- ((marker.type = undefined & showPriceIndicator = true) -> (shouldShowBubble = true) & (shouldShowDot = false)
- ((marker.type = undefined & showPriceIndicator = false) -> (shouldShowBubble = false) & (shouldShowDot = true)
| }) => <div style={{ width: isLarge ? '15rem' : '8.75rem' }}>{children}</div>; | ||
|
|
||
| const SmallerLowPriceRangeExample = () => ( | ||
| // Use case 1: Dot marker (boundaries hidden) |
There was a problem hiding this comment.
Nit, we expect to understand the code through the code itself rather than comments. Your naming is clear enough 👍 , so there's no need for comments here.
Same as below
There was a problem hiding this comment.
Good point! Agreed 🙂 I'll remove these comments now
|
Visit https://backpack.github.io/storybook-prs/4158 to see this build running in a browser. |

Summary
Adds the ability to hide the marker in the
BpkPriceRangecomponent.Storybook
Also expands the API, by introducing an optional
typeproperty of the now optionalmarkerproperty. This intends to replace the already-optionalshowPriceIndicatorproperty, making it clear which marker style we're getting.This PR therefore also deprecates the
showPriceIndicatorproperty. This component accepts any combination of the newmarker.typeandshowPriceIndicatorproperties. The default behaviour (neither property provided) remains the same. Otherwise, the value ofmarker.typewill override the value ofshowPriceIndicator.We expect a follow-up PR corresponding to a major change, where we will remove
showPriceIndicator.This corresponds to Option 4 from the decision document.
Key Changes
markerprop optional - The component can now be used without a markershowPriceIndicatorprop - Marked with JSDoc@deprecatedtagmarker.typeAPI - NewMARKER_DISPLAY_TYPESconstant withBUBBLEandDOToptionsMarkerDisplayTypeand restructured types for claritydocs/migrating-from-showPriceIndicator.mdMotivation
The previous
showPriceIndicatorprop had confusing semantics:The new
marker.typeAPI provides:MARKER_DISPLAY_TYPES.BUBBLEvsMARKER_DISPLAY_TYPES.DOTclearly describes the marker appearanceBUBBLEshows boundaries,DOThides themtypefor an undefined marker.Migration Path (Expand-Migrate-Contract)
This is the expand phase:
marker.typewithMARKER_DISPLAY_TYPES)showPriceIndicator)Changes
Component (
BpkPriceRange.tsx):markerprop optionalmarker.typesupport with newMARKER_DISPLAY_TYPESshowPriceIndicatorwith JSDoc annotationType definitions (
common-types.ts):MarkerDisplayTypetypeMARKER_DISPLAY_TYPESconstantTests:
showPriceIndicatorDocumentation:
docs/migrating-from-showPriceIndicator.md)Examples & Stories:
MARKER_DISPLAY_TYPES.DOTusageTesting
All existing tests pass with backward compatibility maintained. New tests added for:
MARKER_DISPLAY_TYPES.BUBBLEbehaviourMARKER_DISPLAY_TYPES.DOTbehaviourshowPriceIndicatorAccessibility
No accessibility changes - the component maintains the same ARIA attributes and keyboard navigation:
References
packages/bpk-component-price-range/docs/migrating-from-showPriceIndicator.mdRemember to include the following changes:
README.mdupdated🤖 Generated with Claude Code