Skip to content

Commit

Permalink
feat(fluent-ui.com): Document button to increase editPage
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyao27 committed Sep 27, 2019
1 parent 735aea1 commit e0152b3
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/fluent-ui.com/src/components/docs/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createUseStyles } from '@fluent-ui/styles'
import { MenuLine as MenuLineIcon } from '@fluent-ui/icons'

import SideBar from './sidebar'
import EditPage from './editPage'

import Playground from '../playground'
import Highlight from '../highlight'
Expand Down Expand Up @@ -123,6 +124,7 @@ const Content = ({ data }: TemplateProps): React.ReactElement => {
transition: 'all 250ms cubic-bezier(0.4,0,0.2,1) 0ms'
}}
>
<EditPage data={data} />
<Box className={classes.menuButton} display={['block', 'none']}>
<IconButton onClick={mobileMenuDispatch}>{<MenuLineIcon />}</IconButton>
</Box>
Expand Down
35 changes: 35 additions & 0 deletions packages/fluent-ui.com/src/components/docs/editPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react'
import { Button } from '@fluent-ui/core'
import { createUseStyles } from '@fluent-ui/styles'
import { TemplateProps } from '../../templates/docs'
import { useIntl } from 'react-intl'

const SOURCE_CODE_ROOT_URL =
'https://github.com/fluent-org/fluent-ui/blob/master/packages/fluent-ui.com/src'

const useStyles = createUseStyles({
editButton: {
position: 'absolute',
right: 10,
top: 10,
zIndex: 2
}
})

interface EditPageProps {
data: TemplateProps['data']
}

const EditPage: React.FC<EditPageProps> = ({ data }: EditPageProps): React.ReactElement => {
const classes = useStyles()
const { formatMessage } = useIntl()
const markdownLocation = data.doc.fileAbsolutePath
const href = SOURCE_CODE_ROOT_URL + markdownLocation.slice(markdownLocation.lastIndexOf('/docs/'))
return (
<Button className={classes.editButton} as="a" href={href} target="_blank" size="small">
{formatMessage({ id: 'editPage' })}
</Button>
)
}

export default EditPage
6 changes: 6 additions & 0 deletions packages/fluent-ui.com/src/templates/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface TemplateProps {
type: string
langKey: string
}
fileAbsolutePath: string
rawMarkdownBody: string
htmlAst: {
children: {
Expand All @@ -50,6 +51,7 @@ export interface TemplateProps {
title: string
langKey: string
}
fileAbsolutePath: string
rawMarkdownBody: string
}
docs: {
Expand All @@ -63,6 +65,7 @@ export interface TemplateProps {
type: string
langKey: string
}
fileAbsolutePath: string
}
}[]
}
Expand Down Expand Up @@ -121,6 +124,7 @@ export const query = graphql`
type
langKey
}
fileAbsolutePath
rawMarkdownBody
htmlAst
}
Expand All @@ -133,6 +137,7 @@ export const query = graphql`
title
langKey
}
fileAbsolutePath
rawMarkdownBody
}
docs: allMarkdownRemark(filter: { frontmatter: { api: { nin: true } } }) {
Expand All @@ -146,6 +151,7 @@ export const query = graphql`
type
langKey
}
fileAbsolutePath
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/fluent-ui.com/src/translations/translations-zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default {
'nav.feedback': 'Feedback(用户反馈)',
'nav.utils': 'Utils(工具)',
'nav.others': 'Others(其他)',
'nav.hooks': 'react-hooks'
'nav.hooks': 'react-hooks',
editPage: '改进此页面内容'
}
3 changes: 2 additions & 1 deletion packages/fluent-ui.com/src/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default {
'nav.feedback': 'Feedback',
'nav.utils': 'Utils',
'nav.others': 'Others',
'nav.hooks': 'react-hooks'
'nav.hooks': 'react-hooks',
editPage: 'edit this page'
}
6 changes: 4 additions & 2 deletions packages/fluent-ui/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Button: React.FC<ButtonProps> = React.forwardRef<HTMLButtonElement, Button
children,
variant = 'standard',
disabled,
size,
size = 'medium',
block = false,
...rest
} = props
Expand Down Expand Up @@ -48,7 +48,9 @@ Button.displayName = `F${name}`
Button.propTypes = ButtonPropTypes

Button.defaultProps = {
variant: 'standard'
variant: 'standard',
size: 'medium',
block: false
}

export default Button
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ exports[`ItemGroup should render children 1`] = `
justify-content: center;
}
.FItemGroup-titlePrefixAcrylic {
z-index: -1;
z-index: 1;
}
.FItemGroup-titlePrefixNotFloatOpen {
transform: rotate(180deg);
Expand Down
1 change: 1 addition & 0 deletions packages/fluent-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export { colors }
export interface StyledProps {
as?: keyof JSX.IntrinsicElements | React.ComponentType<any>
href?: string
target?: '_self' | '_blank' | '_parent' | '_top'
}

export type StandardProps<
Expand Down

0 comments on commit e0152b3

Please sign in to comment.