Skip to content

Commit

Permalink
Ntrfcs 207 : Map legend open always for desktop (#301)
Browse files Browse the repository at this point in the history
* added showLegendAlwaysOpenForDesktop

* test fixes

* small change

* small change

* format chjanges

* added changeset
  • Loading branch information
SrujanaSaka20 authored Jan 20, 2025
1 parent 1e1d670 commit c8ede68
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-suns-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ticketevolution/seatmaps-client": minor
---

Added showLegendOpenAlwaysForDesktop flag to always display the map legend on desktop when this flag is set to true.
9 changes: 8 additions & 1 deletion packages/seatmaps-client/src/Actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Props {

interface DefaultProps {
showLegend: boolean;
showLegendOpenAlwaysForDesktop: boolean;
showControls: boolean;
onClearSelection(): void;
}
Expand All @@ -43,6 +44,7 @@ export default class Actions extends React.Component<

static defaultProps: DefaultProps = {
showLegend: true,
showLegendOpenAlwaysForDesktop: false,
showControls: true,
onClearSelection: () => {},
};
Expand Down Expand Up @@ -168,7 +170,12 @@ export default class Actions extends React.Component<
)}
{showRightActions && (
<ActionGroup>
<Legend ranges={this.props.ranges} />
<Legend
ranges={this.props.ranges}
showLegendOpenAlwaysForDesktop={
this.props.showLegendOpenAlwaysForDesktop
}
/>
</ActionGroup>
)}
</div>
Expand Down
32 changes: 30 additions & 2 deletions packages/seatmaps-client/src/Legend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Range {
export interface Props {
ranges: Range[];
isMobile?: boolean;
showLegendOpenAlwaysForDesktop?: boolean;
}

interface State {
Expand All @@ -29,6 +30,7 @@ interface State {
export default class Legend extends Component<Props, State> {
static defaultProps = {
isMobile: false,
showLegendOpenAlwaysForDesktop: false,
};

state = {
Expand All @@ -37,9 +39,35 @@ export default class Legend extends Component<Props, State> {

render() {
const { isOpen } = this.state;
const { ranges, isMobile } = this.props;
const { ranges, isMobile, showLegendOpenAlwaysForDesktop } = this.props;

return (
return showLegendOpenAlwaysForDesktop && !isMobile ? (
<div style={{ position: "relative" }}>
<div
style={{
position: "absolute",
backgroundColor: "white",
right: -2,
border: "2px solid lightgray",
borderRadius: "0 0 5px 5px",
}}
>
<h3 style={{ padding: "0 0 0 8px", textAlign: "left" }}>
Map Legend
</h3>
{ranges.map((range) => (
<div key={range.color} style={{ padding: 8, textAlign: "left" }}>
<Swatch color={range.color} style={{ marginRight: 8 }} />
<span>
{formatCurrency(Math.floor(range.min))}
{" - "}
{formatCurrency(Math.ceil(range.max))}
</span>
</div>
))}
</div>
</div>
) : (
<div style={{ position: "relative" }}>
<Button
onClick={() => this.setState({ isOpen: !isOpen })}
Expand Down
4 changes: 4 additions & 0 deletions packages/seatmaps-client/src/TicketMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class TicketMap extends Component<Props & DefaultProps, State> {
},
ticketGroups: [],
showLegend: true,
showLegendOpenAlwaysForDesktop: false,
showControls: true,
mouseControlEnabled: true,
showZoomHelper: true,
Expand Down Expand Up @@ -668,6 +669,9 @@ export class TicketMap extends Component<Props & DefaultProps, State> {
onClearSelection={this.clearSelection}
ranges={$costRanges(this.state, this.props)}
showLegend={this.props.showLegend}
showLegendOpenAlwaysForDesktop={
this.props.showLegendOpenAlwaysForDesktop
}
showControls={this.props.showControls}
onZoomIn={this.handleZoomIn}
onZoomOut={this.handleZoomOut}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`Actions when controls are visible on desktop browsers matches snapshot
ranges={[]}
showControls={true}
showLegend={true}
showLegendOpenAlwaysForDesktop={false}
>
<div
data-testid="seatmaps-actions-menu"
Expand Down Expand Up @@ -251,6 +252,7 @@ exports[`Actions when controls are visible on desktop browsers matches snapshot
<Legend
isMobile={false}
ranges={[]}
showLegendOpenAlwaysForDesktop={false}
>
<div
style={
Expand Down Expand Up @@ -314,6 +316,7 @@ exports[`Actions when controls are visible on mobile browsers matches snapshot 1
ranges={[]}
showControls={true}
showLegend={true}
showLegendOpenAlwaysForDesktop={false}
>
<div
data-testid="seatmaps-actions-menu"
Expand Down Expand Up @@ -556,6 +559,7 @@ exports[`Actions when controls are visible on mobile browsers matches snapshot 1
<Legend
isMobile={false}
ranges={[]}
showLegendOpenAlwaysForDesktop={false}
>
<div
style={
Expand Down
1 change: 1 addition & 0 deletions packages/seatmaps-client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const optionalConfigKeys: (keyof DefaultProps)[] = [
"sectionPercentiles",
"mapsDomain",
"showControls",
"showLegendOpenAlwaysForDesktop",
"showLegend",
"mouseControlEnabled",
"showZoomHelper",
Expand Down
1 change: 1 addition & 0 deletions packages/seatmaps-client/src/types/TicketMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface DefaultProps {
mapsDomain: string;
onSelection(sections: string[]): void;
showControls: boolean;
showLegendOpenAlwaysForDesktop: boolean;
mouseControlEnabled: boolean;
showZoomHelper: boolean;
missingSeatMapLogo?: React.ReactNode;
Expand Down

0 comments on commit c8ede68

Please sign in to comment.