Skip to content
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

chore: add example component #1446

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions collections/forms/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-05-05T12:46:11.864Z\n"
"PO-Revision-Date: 2023-05-05T12:46:11.864Z\n"
"POT-Creation-Date: 2024-01-24T11:34:21.463Z\n"
"PO-Revision-Date: 2024-01-24T11:34:21.469Z\n"

msgid "Upload file"
msgstr "Upload file"
Expand Down
4 changes: 2 additions & 2 deletions components/button/src/button/__tests__/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('<Button>', () => {
const dataTest = 'dhis2-uicore-button'
const wrapper = mount(<Button dataTest={dataTest} />)

const actual = wrapper.find({ 'data-test': dataTest })
const actual = wrapper.find('button').find({ 'data-test': dataTest })

expect(actual.length).toBe(1)
})
Expand All @@ -17,7 +17,7 @@ describe('<Button>', () => {
const dataTest = 'button-data-test'
const wrapper = mount(<Button dataTest={dataTest} />)

const actual = wrapper.find({ 'data-test': dataTest })
const actual = wrapper.find('button').find({ 'data-test': dataTest })

expect(actual.length).toBe(1)
})
Expand Down
11 changes: 6 additions & 5 deletions components/button/src/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect, useRef } from 'react'
import styles from './button.styles.js'
import { NativeButton } from '../index.js'
import { className as styledClassName, styles } from './button.styles.js'

export const Button = ({
children,
Expand Down Expand Up @@ -34,7 +35,7 @@
if (initialFocus && ref.current) {
ref.current.focus()
}
}, [initialFocus, ref.current])

Check warning on line 38 in components/button/src/button/button.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has an unnecessary dependency: 'ref.current'. Either exclude it or remove the dependency array. Mutable values like 'ref.current' aren't valid dependencies because mutating them doesn't re-render the component

const handleClick = (event) => onClick && onClick({ value, name }, event)
const handleBlur = (event) => onBlur && onBlur({ value, name }, event)
Expand All @@ -43,7 +44,7 @@
onKeyDown && onKeyDown({ value, name }, event)

const iconOnly = icon && !children
const buttonClassName = cx(className, {
const buttonClassName = cx(className, styledClassName, {
primary,
secondary,
destructive,
Expand All @@ -55,7 +56,7 @@
})

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

Expand Down
73 changes: 1 addition & 72 deletions components/button/src/button/button.styles.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,7 @@
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};
}

export const { className, styles } = css.resolve`
.small {
height: 28px;
padding: 0 6px;
Expand Down
1 change: 1 addition & 0 deletions components/button/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Button } from './button/index.js'
export { NativeButton } from './native-button/index.js'
export { ButtonStrip } from './button-strip/index.js'
export { SplitButton } from './split-button/index.js'
export { DropdownButton } from './dropdown-button/index.js'
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'
20 changes: 20 additions & 0 deletions components/button/src/native-button/native-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PropTypes from 'prop-types'
import React, { forwardRef } from 'react'
import styles from './native-button.styles.js'

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

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

NativeButton.propTypes = {
/** Component to render inside the button */
children: PropTypes.node,
className: PropTypes.string,
}
15 changes: 15 additions & 0 deletions components/button/src/native-button/native-button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { NativeButton } from './native-button.js'

export default {
title: 'Native Button',
component: NativeButton,
}

const Template = (args) => <NativeButton {...args} />

export const Basic = Template.bind({})
Basic.args = {
name: 'Basic button',
children: 'Label me!',
}
71 changes: 71 additions & 0 deletions components/button/src/native-button/native-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};
}
`
Loading