Skip to content

Commit

Permalink
chore: add example component
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Jan 24, 2024
1 parent a2d2fc6 commit 6b6a824
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 73 deletions.
5 changes: 3 additions & 2 deletions components/button/src/button/button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CircularLoader } from '@dhis2-ui/loader'
import { sharedPropTypes } from '@dhis2/ui-constants'
import { NativeButton } from '../index.js'

Check failure on line 3 in components/button/src/button/button.js

View workflow job for this annotation

GitHub Actions / lint

`../index.js` import should occur after import of `react`

Check failure on line 3 in components/button/src/button/button.js

View workflow job for this annotation

GitHub Actions / lint

NativeButton not found in '../index.js'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect, useRef } from 'react'
Expand Down Expand Up @@ -55,7 +56,7 @@ export const Button = ({
})

return (
<button
<NativeButton
ref={ref}
name={name}
className={buttonClassName}
Expand All @@ -80,7 +81,7 @@ export const Button = ({
{icon && <span className="button-icon">{icon}</span>}
{children}
<style jsx>{styles}</style>
</button>
</NativeButton>
)
}

Expand Down
71 changes: 0 additions & 71 deletions components/button/src/button/button.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,6 @@ import { colors, theme, spacers } from '@dhis2/ui-constants'
import css from 'styled-jsx/css'

export default css`
button {
display: inline-flex;
position: relative;
align-items: center;
justify-content: center;
border-radius: 4px;
font-weight: 400;
letter-spacing: 0.5px;
text-decoration: none;
cursor: pointer;
user-select: none;
color: ${colors.grey900};
/*medium*/
height: 36px;
padding: 0 ${spacers.dp12};
font-size: 14px;
line-height: 16px;
/*basic*/
border: 1px solid ${colors.grey500};
background-color: #f9fafb;
}
button:disabled {
cursor: not-allowed;
}
button:focus {
outline: 3px solid ${theme.focus};
outline-offset: -3px;
text-decoration: underline;
}
/* Prevent focus styles when mouse clicking */
button:focus:not(:focus-visible) {
outline: none;
text-decoration: none;
}
/* Prevent focus styles on active and disabled buttons */
button:active:focus,
button:disabled:focus {
outline: none;
text-decoration: none;
}
button:hover {
border-color: ${colors.grey500};
background-color: ${colors.grey200};
}
button:active,
button:active:focus {
border-color: ${colors.grey500};
background-color: ${colors.grey200};
box-shadow: 0 0 0 1px rgb(0, 0, 0, 0.1) inset;
}
button:focus {
background-color: #f9fafb;
}
button:disabled {
border-color: ${colors.grey400};
background-color: #f9fafb;
box-shadow: none;
color: ${theme.disabled};
fill: ${theme.disabled};
}
.small {
height: 28px;
padding: 0 6px;
Expand Down
71 changes: 71 additions & 0 deletions components/button/src/native-button/button.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { colors, theme, spacers } from '@dhis2/ui-constants'
import css from 'styled-jsx/css'

export default css`
button {
display: inline-flex;
position: relative;
align-items: center;
justify-content: center;
border-radius: 4px;
font-weight: 400;
letter-spacing: 0.5px;
text-decoration: none;
cursor: pointer;
user-select: none;
color: ${colors.grey900};
height: 36px;
padding: 0 ${spacers.dp12};
font-size: 14px;
line-height: 16px;
border: 1px solid ${colors.grey500};
background-color: #f9fafb;
}
button:disabled {
cursor: not-allowed;
}
button:focus {
outline: 3px solid ${theme.focus};
outline-offset: -3px;
text-decoration: underline;
}
/* Prevent focus styles when mouse clicking */
button:focus:not(:focus-visible) {
outline: none;
text-decoration: none;
}
/* Prevent focus styles on active and disabled buttons */
button:active:focus,
button:disabled:focus {
outline: none;
text-decoration: none;
}
button:hover {
border-color: ${colors.grey500};
background-color: ${colors.grey200};
}
button:active,
button:active:focus {
border-color: ${colors.grey500};
background-color: ${colors.grey200};
box-shadow: 0 0 0 1px rgb(0, 0, 0, 0.1) inset;
}
button:focus {
background-color: #f9fafb;
}
button:disabled {
border-color: ${colors.grey400};
background-color: #f9fafb;
box-shadow: none;
color: ${theme.disabled};
fill: ${theme.disabled};
}
`
1 change: 1 addition & 0 deletions components/button/src/native-button/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NativeButton } from './native-button.js'
19 changes: 19 additions & 0 deletions components/button/src/native-button/native-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import PropTypes from 'prop-types'
import React, { forwardRef } from 'react'
import styles from './button.styles.js'

export const NativeButton = forwardRef(function NativeButton(props, ref) {
const { children, ...rest } = props

return (
<button ref={ref} {...rest}>
{children}
<style jsx>{styles}</style>
</button>
)
})

NativeButton.propTypes = {
/** Component to render inside the button */
children: PropTypes.node,
}

0 comments on commit 6b6a824

Please sign in to comment.