-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #859 from opentripplanner/external-link-icons
Clarify Links That Open in New Window
- Loading branch information
Showing
7 changed files
with
190 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,105 @@ | ||
import { Checkbox, ControlLabel, FormGroup } from 'react-bootstrap' | ||
import { connect } from 'react-redux' | ||
import { FormattedMessage, useIntl } from 'react-intl' | ||
import React, { FormEventHandler } from 'react' | ||
|
||
import { LinkOpensNewWindow } from '../util/externalLink' | ||
import { | ||
TERMS_OF_SERVICE_PATH, | ||
TERMS_OF_STORAGE_PATH | ||
} from '../../util/constants' | ||
|
||
/** | ||
* User terms of use pane. | ||
*/ | ||
const TermsOfUsePane = ({ | ||
disableCheckTerms, | ||
handleBlur, | ||
handleChange, | ||
values: userData | ||
}: { | ||
disableCheckTerms: boolean | ||
handleBlur: () => void | ||
handleChange: FormEventHandler<Checkbox> | ||
values: { | ||
hasConsentedToTerms: boolean | ||
storeTripHistory: boolean | ||
} | ||
}) => { | ||
const intl = useIntl() | ||
const { hasConsentedToTerms, storeTripHistory } = userData | ||
|
||
return ( | ||
<div> | ||
<ControlLabel> | ||
<FormattedMessage id="components.TermsOfUsePane.mustAgreeToTerms" /> | ||
</ControlLabel> | ||
<FormGroup> | ||
<Checkbox | ||
checked={hasConsentedToTerms} | ||
disabled={disableCheckTerms} | ||
name="hasConsentedToTerms" | ||
onBlur={disableCheckTerms ? undefined : handleBlur} | ||
onChange={disableCheckTerms ? undefined : handleChange} | ||
> | ||
<FormattedMessage | ||
id="components.TermsOfUsePane.termsOfServiceStatement" | ||
values={{ | ||
termsOfUseLink: (contents: JSX.Element) => ( | ||
<LinkOpensNewWindow | ||
contents={contents} | ||
inline | ||
url={`/#${TERMS_OF_SERVICE_PATH}`} | ||
/> | ||
) | ||
}} | ||
/> | ||
</Checkbox> | ||
</FormGroup> | ||
<FormGroup> | ||
<Checkbox | ||
checked={storeTripHistory} | ||
name="storeTripHistory" | ||
onBlur={handleBlur} | ||
onChange={(e) => { | ||
// Show alert when user is unchecking the checkbox | ||
if (storeTripHistory) { | ||
// Do nothing if the user hits cancel | ||
if ( | ||
// eslint-disable-next-line no-restricted-globals | ||
!confirm( | ||
intl.formatMessage({ | ||
id: 'components.TermsOfUsePane.confirmDeletionPrompt' | ||
}) | ||
) | ||
) { | ||
return | ||
} | ||
} | ||
|
||
handleChange(e) | ||
}} | ||
> | ||
<FormattedMessage | ||
id="components.TermsOfUsePane.termsOfStorageStatement" | ||
values={{ | ||
termsOfStorageLink: (contents: JSX.Element) => ( | ||
<LinkOpensNewWindow | ||
contents={contents} | ||
inline | ||
url={`/#${TERMS_OF_STORAGE_PATH}`} | ||
/> | ||
) | ||
}} | ||
/> | ||
</Checkbox> | ||
</FormGroup> | ||
</div> | ||
) | ||
} | ||
const mapStateToProps = (state: any) => { | ||
return { | ||
termsOfStorageSet: state.otp.config.persistence?.terms_of_storage | ||
} | ||
} | ||
export default connect(mapStateToProps)(TermsOfUsePane) |
This file contains 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,62 @@ | ||
import { ExternalLinkAlt } from '@styled-icons/fa-solid' | ||
import { useIntl } from 'react-intl' | ||
import React, { HTMLAttributes } from 'react' | ||
|
||
interface LinkProps extends HTMLAttributes<HTMLElement> { | ||
contents: JSX.Element | string | ||
gap?: number | ||
inline?: boolean | ||
size?: number | ||
style?: React.CSSProperties | ||
url: string | ||
} | ||
|
||
interface IconProps extends HTMLAttributes<HTMLElement> { | ||
size?: number | ||
style?: React.CSSProperties | ||
} | ||
|
||
export const NewWindowIconA11y = ({ | ||
size = 14, | ||
style | ||
}: IconProps): JSX.Element => { | ||
const intl = useIntl() | ||
return ( | ||
<ExternalLinkAlt | ||
/* the "title" prop removes aria-hidden from styled-icons, so use the title as the aria-label as well | ||
https://github.com/styled-icons/styled-icons#accessibility */ | ||
aria-labelledby="title" | ||
height={size} | ||
style={style} | ||
title={intl.formatMessage({ id: 'common.linkOpensNewWindow' })} | ||
/> | ||
) | ||
} | ||
|
||
export const LinkOpensNewWindow = ({ | ||
contents, | ||
gap = 6, | ||
inline, | ||
size = 14, | ||
style, | ||
url | ||
}: LinkProps): JSX.Element => { | ||
return ( | ||
<a | ||
href={url} | ||
rel="noreferrer" | ||
style={{ | ||
alignItems: 'center', | ||
display: `${inline ? 'inline-flex' : 'flex'}`, | ||
flexDirection: 'row', | ||
gap, | ||
whiteSpace: 'nowrap', | ||
...style | ||
}} | ||
target="_blank" | ||
> | ||
{contents} | ||
<NewWindowIconA11y size={size} /> | ||
</a> | ||
) | ||
} |
This file contains 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