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
a1b6559f
Commit
a1b6559f
authored
Dec 13, 2019
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `IconButton` component
parent
0063b931
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
0 deletions
+134
-0
icon-button.js
src/sidebar/components/icon-button.js
+46
-0
icon-button-test.js
src/sidebar/components/test/icon-button-test.js
+66
-0
icon-button.scss
src/styles/sidebar/components/icon-button.scss
+21
-0
sidebar.scss
src/styles/sidebar/sidebar.scss
+1
-0
No files found.
src/sidebar/components/icon-button.js
0 → 100644
View file @
a1b6559f
'use strict'
;
const
classnames
=
require
(
'classnames'
);
const
propTypes
=
require
(
'prop-types'
);
const
{
createElement
}
=
require
(
'preact'
);
const
SvgIcon
=
require
(
'./svg-icon'
);
/**
* A simple icon-only button
*/
function
IconButton
({
className
=
''
,
icon
,
isActive
=
false
,
title
,
onClick
=
()
=>
null
,
})
{
return
(
<
button
className
=
{
classnames
(
'icon-button'
,
className
,
{
'is-active'
:
isActive
,
})}
onClick
=
{
onClick
}
aria
-
pressed
=
{
isActive
}
title
=
{
title
}
>
<
SvgIcon
name
=
{
icon
}
className
=
"icon-button__icon"
/>
<
/button
>
);
}
IconButton
.
propTypes
=
{
/** Optional additional class(es) to apply to the component element */
className
:
propTypes
.
string
,
/** The name of the SVGIcon to render */
icon
:
propTypes
.
string
.
isRequired
,
/** Is this button currently in an "active" or "on" state? */
isActive
:
propTypes
.
bool
,
/** a value used for the `title` and `aria-label` attributes */
title
:
propTypes
.
string
.
isRequired
,
/** optional callback for clicks */
onClick
:
propTypes
.
func
,
};
module
.
exports
=
IconButton
;
src/sidebar/components/test/icon-button-test.js
0 → 100644
View file @
a1b6559f
'use strict'
;
const
{
createElement
}
=
require
(
'preact'
);
const
{
mount
}
=
require
(
'enzyme'
);
const
IconButton
=
require
(
'../icon-button'
);
const
mockImportedComponents
=
require
(
'./mock-imported-components'
);
describe
(
'IconButton'
,
()
=>
{
let
fakeOnClick
;
function
createComponent
(
props
=
{})
{
return
mount
(
<
IconButton
icon
=
"fakeIcon"
isActive
=
{
false
}
title
=
"My Action"
onClick
=
{
fakeOnClick
}
{...
props
}
/
>
);
}
beforeEach
(()
=>
{
fakeOnClick
=
sinon
.
stub
();
IconButton
.
$imports
.
$mock
(
mockImportedComponents
());
});
afterEach
(()
=>
{
IconButton
.
$imports
.
$restore
();
});
it
(
'adds active className if `isActive` is `true`'
,
()
=>
{
const
wrapper
=
createComponent
({
isActive
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
'is-active'
));
});
it
(
'renders `SvgIcon` for associated icon'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
});
it
(
'sets ARIA `aria-pressed` attribute if `isActive`'
,
()
=>
{
const
wrapper
=
createComponent
({
isActive
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
prop
(
'aria-pressed'
));
});
it
(
'invokes `onClick` callback when pressed'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
assert
.
calledOnce
(
fakeOnClick
);
});
it
(
'adds additional class name passed in `className` prop'
,
()
=>
{
const
wrapper
=
createComponent
({
className
:
'my-class'
});
assert
.
isTrue
(
wrapper
.
hasClass
(
'my-class'
));
});
it
(
'sets compact style if `useCompactStyle` is set`'
,
()
=>
{
const
wrapper
=
createComponent
({
useCompactStyle
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
'icon-button--compact'
));
});
});
src/styles/sidebar/components/icon-button.scss
0 → 100644
View file @
a1b6559f
@use
"../../mixins/buttons"
;
@use
"../../variables"
as
var
;
.icon-button
{
@include
buttons
.
button-base
;
&
.is-active
{
color
:
var
.
$brand
;
&
:hover
{
color
:
var
.
$brand
;
}
}
}
@media
(
pointer
:
coarse
)
{
.icon-button
{
min-width
:
var
.
$touch-target-size
;
min-height
:
var
.
$touch-target-size
;
}
}
src/styles/sidebar/sidebar.scss
View file @
a1b6559f
...
...
@@ -43,6 +43,7 @@
@use
'./components/group-list'
;
@use
'./components/group-list-item'
;
@use
'./components/help-panel'
;
@use
'./components/icon-button'
;
@use
'./components/logged-out-message'
;
@use
'./components/markdown-editor'
;
@use
'./components/markdown-view'
;
...
...
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