This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
203 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {IOfficeLinkStyleProps, IOfficeLinkStyles} from "@/components/Link/OfficeLink.types"; | ||
import {HighContrastSelector, HighContrastSelectorBlack, HighContrastSelectorWhite} from "@/styling"; | ||
import {IsFocusVisibleClassName} from "@/styling/styles/getFocusStyle"; | ||
import {getGlobalClassNames} from "@/styling/styles/getGlobalClassNames"; | ||
|
||
const GlobalClassNames = { | ||
root: "ms-Link" | ||
}; | ||
|
||
export const getStyles = (props: IOfficeLinkStyleProps): IOfficeLinkStyles => { | ||
const { className, isButton, isDisabled, theme } = props; | ||
const { semanticColors } = theme; | ||
|
||
const classNames = getGlobalClassNames(GlobalClassNames, theme); | ||
|
||
return { | ||
root: [ | ||
classNames.root, | ||
theme.fonts.medium, | ||
{ | ||
color: semanticColors.link, | ||
outline: "none", | ||
fontSize: "inherit", | ||
fontWeight: "inherit", | ||
selectors: { | ||
[`.${IsFocusVisibleClassName} &:focus`]: { | ||
// Can't use getFocusStyle because it doesn't support wrapping links | ||
// https://github.com/OfficeDev/office-ui-fabric-react/issues/4883#issuecomment-406743543 | ||
outline: `1px solid ${theme.palette.neutralSecondary}` | ||
} | ||
} | ||
}, | ||
isButton && { | ||
background: "none", | ||
backgroundColor: "transparent", | ||
border: "none", | ||
cursor: "pointer", | ||
display: "inline", | ||
margin: 0, | ||
overflow: "inherit", | ||
padding: 0, | ||
textAlign: "left", | ||
textOverflow: "inherit", | ||
userSelect: "text", | ||
borderBottom: "1px solid transparent", // For Firefox high contrast mode | ||
selectors: { | ||
[HighContrastSelectorBlack]: { | ||
color: "#FFFF00" | ||
}, | ||
[HighContrastSelectorWhite]: { | ||
color: "#00009F" | ||
}, | ||
"@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none)": { | ||
// For IE high contrast mode | ||
borderBottom: "none" | ||
} | ||
} | ||
}, | ||
!isButton && { | ||
textDecoration: "none" | ||
}, | ||
isDisabled && [ | ||
"is-disabled", | ||
{ | ||
color: semanticColors.disabledText, | ||
cursor: "default" | ||
}, | ||
{ | ||
selectors: { | ||
"&:link, &:visited": { | ||
pointerEvents: "none" | ||
} | ||
} | ||
} | ||
], | ||
!isDisabled && { | ||
selectors: { | ||
"&:active, &:hover, &:active:hover": { | ||
color: semanticColors.linkHovered, | ||
selectors: { | ||
[HighContrastSelector]: { | ||
textDecoration: "underline" | ||
} | ||
} | ||
}, | ||
"&:focus": { | ||
color: semanticColors.link | ||
} | ||
} | ||
}, | ||
classNames.root, | ||
className | ||
] | ||
}; | ||
}; |
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,43 @@ | ||
import {ITheme} from "@/styling"; | ||
import {IStyle} from "@uifabric/merge-styles"; | ||
|
||
export interface IOfficeLinkHTMLAttributes<T> { | ||
// Shared | ||
type?: string; | ||
|
||
// Anchor | ||
download?: any; | ||
href?: string; | ||
hrefLang?: string; | ||
media?: string; | ||
rel?: string; | ||
target?: string; | ||
|
||
// Button | ||
autoFocus?: boolean; | ||
disabled?: boolean; | ||
form?: string; | ||
formAction?: string; | ||
formEncType?: string; | ||
formMethod?: string; | ||
formNoValidate?: boolean; | ||
formTarget?: string; | ||
name?: string; | ||
value?: string | string[] | number; | ||
} | ||
|
||
export interface IOfficeLinkProps { | ||
disabled?: boolean; | ||
href?: string; | ||
} | ||
|
||
export interface IOfficeLinkStyleProps { | ||
className?: string; | ||
isButton?: boolean; | ||
isDisabled?: boolean; | ||
theme: ITheme; | ||
} | ||
|
||
export interface IOfficeLinkStyles { | ||
root: IStyle; | ||
} |
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,46 @@ | ||
<template> | ||
<component :is="rootType" v-bind="rootProps" @click="onClick"> | ||
<slot/> | ||
</component> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {getStyles} from "@/components/Link/OfficeLink.styles"; | ||
import {IOfficeLinkProps} from "@/components/Link/OfficeLink.types"; | ||
import {loadTheme} from "@/styling"; | ||
import {mergeStyleSets} from "@uifabric/merge-styles"; | ||
import {Component, Prop, Vue} from "vue-property-decorator"; | ||
@Component | ||
export default class OfficeLink extends Vue implements IOfficeLinkProps { | ||
@Prop({type: Boolean}) public disabled!: boolean; | ||
@Prop({type: String, default: null}) public href?: string; | ||
private get rootType() { | ||
return this.href ? "a" : "button"; | ||
} | ||
private get rootProps() { | ||
return { | ||
"class": this.classNames.root, | ||
"href": this.href ? this.href : undefined | ||
}; | ||
} | ||
private onClick(evnt: MouseEvent) { | ||
if (this.disabled) { | ||
evnt.preventDefault(); | ||
} else { | ||
this.$emit("click", evnt); | ||
} | ||
} | ||
private get classNames() { | ||
return mergeStyleSets(getStyles({ | ||
theme: loadTheme({}), | ||
isButton: !this.href, | ||
isDisabled: this.disabled | ||
})); | ||
} | ||
} | ||
</script> |
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