-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[TimezonePicker] Support a custom target via <children> #3287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d42847
Export getTimezoneMetadata(), add default value for date parameter
cmslewis 3db773f
Support one custom child in <TimezonePicker>
cmslewis dcf1ee2
Update example
cmslewis 06f207b
Update tests
cmslewis 74791d3
(nit) Rename to CustomTimezonePickerTarget
cmslewis 3d7905b
Add more docs about possibly ignored props
cmslewis 8b400f6
Update docs
cmslewis abbd36c
Respond to @giladgray CR
cmslewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/docs-app/src/examples/timezone-examples/components/customTimezoneTarget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the terms of the LICENSE file distributed with this project. | ||
| */ | ||
|
|
||
| import { Colors, Icon, Intent, Tooltip } from "@blueprintjs/core"; | ||
| import { IconNames } from "@blueprintjs/icons"; | ||
| import { getTimezoneMetadata } from "@blueprintjs/timezone"; | ||
| import React from "react"; | ||
|
|
||
| export interface ICustomTimezonePickerTargetProps { | ||
| timezone: string; | ||
| } | ||
|
|
||
| export interface ICustomTimezonePickerTargetState { | ||
| isHovering: boolean; | ||
| } | ||
|
|
||
| // This is a little component that isn't meant to see the light of day outside | ||
| // the TimezonePickerExample. Coding style is thus a *little* scrappy. | ||
| export class CustomTimezonePickerTarget extends React.PureComponent< | ||
| ICustomTimezonePickerTargetProps, | ||
| ICustomTimezonePickerTargetState | ||
| > { | ||
| public state: ICustomTimezonePickerTargetState = { | ||
| isHovering: false, | ||
| }; | ||
|
|
||
| public render() { | ||
| const { isHovering } = this.state; | ||
| return ( | ||
| <Tooltip content={this.getTooltipContent()}> | ||
| <div | ||
| onMouseEnter={this.handleMouseEnter} | ||
| onMouseLeave={this.handleMouseLeave} | ||
| style={{ cursor: "pointer" }} | ||
| > | ||
| <Icon icon={IconNames.GLOBE} intent={isHovering ? Intent.PRIMARY : undefined} /> | ||
| | ||
| <Icon color={Colors.GRAY1} icon={IconNames.CARET_DOWN} /> | ||
| </div> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
|
|
||
| private getTooltipContent() { | ||
| const { timezone } = this.props; | ||
|
|
||
| if (timezone == null || timezone.length === 0) { | ||
| return "No selection"; | ||
| } | ||
|
|
||
| const { abbreviation, offsetAsString } = getTimezoneMetadata(timezone); | ||
|
|
||
| return ( | ||
| <span> | ||
| GMT {offsetAsString} | ||
| <span style={{ color: Colors.GRAY4 }}>{abbreviation ? ` (${abbreviation})` : ""}</span> | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| private handleMouseEnter = () => this.setState({ isHovering: true }); | ||
| private handleMouseLeave = () => this.setState({ isHovering: false }); | ||
| } |
7 changes: 7 additions & 0 deletions
7
packages/docs-app/src/examples/timezone-examples/components/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* | ||
| * Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the terms of the LICENSE file distributed with this project. | ||
| */ | ||
|
|
||
| export * from "./customTimezoneTarget"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* | ||
| * Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the terms of the LICENSE file distributed with this project. | ||
| */ | ||
|
|
||
| const ns = "[Blueprint]"; | ||
|
|
||
| export const TIMEZONE_PICKER_WARN_TOO_MANY_CHILDREN = | ||
| ns + | ||
| ` <TimezonePicker> supports up to one child; additional children are ignored.` + | ||
| ` If a child is present, it it will be rendered in place of the default button target.`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.