Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
d3ef7988
Commit
d3ef7988
authored
Apr 05, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Apr 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `size` property, more `variant` options to `*Button` components
parent
27b0913e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
9 deletions
+44
-9
buttons.js
src/shared/components/buttons.js
+13
-6
buttons-test.js
src/shared/components/test/buttons-test.js
+31
-3
No files found.
src/shared/components/buttons.js
View file @
d3ef7988
...
...
@@ -15,9 +15,11 @@ import { SvgIcon } from '@hypothesis/frontend-shared';
* @prop {boolean} [pressed] - Is this button currently "active?" (set
* `aria-pressed`)
* @prop {() => any} [onClick]
* @prop {'small'|'medium'|'large'} [size='medium'] - Relative button size:
* affects padding
* @prop {Object} [style] - Optional inline styles
* @prop {string} [title] - Button title; used for `aria-label` attribute
* @prop {'
primary'} [variant
] - For styling: element variant
* @prop {'
normal'|'primary'|'light'|'dark'} [variant='normal'
] - For styling: element variant
*/
/**
...
...
@@ -42,9 +44,10 @@ function ButtonBase({
expanded
,
pressed
,
onClick
=
()
=>
{},
size
=
'medium'
,
style
=
{},
title
,
variant
,
variant
=
'normal'
,
})
{
const
otherAttributes
=
{};
if
(
typeof
disabled
===
'boolean'
)
{
...
...
@@ -64,10 +67,14 @@ function ButtonBase({
return
(
<
button
className
=
{
classnames
(
className
,
{
[
`
${
className
}
--
${
variant
}
`
]:
variant
,
[
`
${
className
}
--icon-
${
iconPosition
}
`
]:
icon
,
})}
className
=
{
classnames
(
className
,
`
${
className
}
--
${
size
}
`
,
`
${
className
}
--
${
variant
}
`
,
{
[
`
${
className
}
--icon-
${
iconPosition
}
`
]:
icon
,
}
)}
onClick
=
{
onClick
}
{...
otherAttributes
}
style
=
{
style
}
...
...
src/shared/components/test/buttons-test.js
View file @
d3ef7988
...
...
@@ -41,11 +41,39 @@ function addCommonTests({ componentName, createComponentFn, withIcon = true }) {
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
componentName
));
});
it
(
'renders a primary variant'
,
()
=>
{
const
wrapper
=
createComponentFn
({
variant
:
'primary'
});
[
'primary'
,
'light'
,
'dark'
].
forEach
(
variant
=>
{
it
(
'renders a valid variant'
,
()
=>
{
const
wrapper
=
createComponentFn
({
variant
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
`
${
componentName
}
--
${
variant
}
`
)
);
});
});
it
(
'sets a `normal` variant modifier class by default'
,
()
=>
{
const
wrapper
=
createComponentFn
();
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
`
${
componentName
}
--normal`
)
);
});
[
'small'
,
'medium'
,
'large'
].
forEach
(
size
=>
{
it
(
'renders a valid size'
,
()
=>
{
const
wrapper
=
createComponentFn
({
size
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
`
${
componentName
}
--
${
size
}
`
)
);
});
});
it
(
'sets a `medium` size modifier class by default'
,
()
=>
{
const
wrapper
=
createComponentFn
();
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
`
${
componentName
}
--
primary
`
)
wrapper
.
find
(
'button'
).
hasClass
(
`
${
componentName
}
--
medium
`
)
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment