-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2b7dc0
commit 311ba67
Showing
24 changed files
with
2,010 additions
and
25 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/js-packages/components/changelog/add-threats-data-view-component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add ThreatsDataView component |
39 changes: 39 additions & 0 deletions
39
projects/js-packages/components/components/badge/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import styles from './style.module.scss'; | ||
|
||
type BadgeProps = { | ||
children?: React.ReactNode; | ||
className?: string; | ||
variant?: 'success' | 'warning' | 'danger'; | ||
[ key: string ]: unknown; | ||
}; | ||
|
||
/** | ||
* Badge component | ||
* | ||
* @param {object} props - The component properties. | ||
* @param {string} props.variant - The badge variant (i.e. 'success', 'warning', 'danger'). | ||
* @param {JSX.Element} props.children - Badge text or content. | ||
* @param {string} props.className - Additional class name to pass to the Badge component. | ||
* | ||
* @return {React.ReactElement} The `Badge` component. | ||
*/ | ||
const Badge: React.FC< BadgeProps > = ( { children, className, variant = 'info', ...props } ) => { | ||
const classes = clsx( | ||
styles.badge, | ||
{ | ||
[ styles[ 'is-success' ] ]: variant === 'success', | ||
[ styles[ 'is-warning' ] ]: variant === 'warning', | ||
[ styles[ 'is-danger' ] ]: variant === 'danger', | ||
}, | ||
className | ||
); | ||
return ( | ||
<span className={ classes } { ...props }> | ||
{ children } | ||
</span> | ||
); | ||
}; | ||
|
||
export default Badge; |
22 changes: 22 additions & 0 deletions
22
projects/js-packages/components/components/badge/stories/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Badge from '../index'; | ||
|
||
export default { | ||
title: 'JS Packages/Components/Badge', | ||
component: Badge, | ||
argTypes: { | ||
type: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: [ 'info', 'danger', 'warning', 'success' ], | ||
}, | ||
}, | ||
}; | ||
|
||
const Template = args => <Badge { ...args } />; | ||
|
||
export const _default = Template.bind( {} ); | ||
_default.args = { | ||
type: 'info', | ||
children: 'Hello World', | ||
}; |
25 changes: 25 additions & 0 deletions
25
projects/js-packages/components/components/badge/style.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.badge { | ||
display: inline-block; | ||
border-radius: 4px; | ||
background-color: var(--jp-gray-0); | ||
color: var(--jp-gray-80); | ||
padding: 4px 8px; | ||
font-size: 13px; | ||
font-weight: 400; | ||
line-height: 16px; | ||
|
||
&.is-success { | ||
background-color: var(--jp-green-5); | ||
color: var(--jp-green-50); | ||
} | ||
|
||
&.is-warning { | ||
background-color: var(--jp-yellow-5); | ||
color: var(--jp-yellow-60); | ||
} | ||
|
||
&.is-danger { | ||
background-color: var(--jp-red-5); | ||
color: var(--jp-red-70); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 14 additions & 24 deletions
38
projects/js-packages/components/components/threat-severity-badge/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,24 @@ | ||
import { _x } from '@wordpress/i18n'; | ||
import styles from './styles.module.scss'; | ||
import Badge from '../badge'; | ||
|
||
const severityClassNames = severity => { | ||
const ThreatSeverityBadge = ( { severity } ) => { | ||
if ( severity >= 5 ) { | ||
return 'is-critical'; | ||
} else if ( severity >= 3 && severity < 5 ) { | ||
return 'is-high'; | ||
return ( | ||
<Badge variant="danger"> | ||
{ _x( 'Critical', 'Severity label for issues rated 5 or higher.', 'jetpack' ) } | ||
</Badge> | ||
); | ||
} | ||
return 'is-low'; | ||
}; | ||
|
||
const severityText = severity => { | ||
if ( severity >= 5 ) { | ||
return _x( 'Critical', 'Severity label for issues rated 5 or higher.', 'jetpack' ); | ||
} else if ( severity >= 3 && severity < 5 ) { | ||
return _x( 'High', 'Severity label for issues rated between 3 and 5.', 'jetpack' ); | ||
if ( severity >= 3 && severity < 5 ) { | ||
return ( | ||
<Badge variant="warning"> | ||
{ _x( 'High', 'Severity label for issues rated between 3 and 5.', 'jetpack' ) } | ||
</Badge> | ||
); | ||
} | ||
return _x( 'Low', 'Severity label for issues rated below 3.', 'jetpack' ); | ||
}; | ||
|
||
const ThreatSeverityBadge = ( { severity } ) => { | ||
return ( | ||
<div | ||
className={ `${ styles[ 'threat-severity-badge' ] } ${ | ||
styles[ severityClassNames( severity ) ] | ||
}` } | ||
> | ||
{ severityText( severity ) } | ||
</div> | ||
); | ||
return <Badge>{ _x( 'Low', 'Severity label for issues rated below 3.', 'jetpack' ) }</Badge>; | ||
}; | ||
|
||
export default ThreatSeverityBadge; |
18 changes: 18 additions & 0 deletions
18
projects/js-packages/components/components/threats-data-views/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export const PAID_PLUGIN_SUPPORT_URL = 'https://jetpack.com/contact-support/?rel=support'; | ||
|
||
export const THREAT_STATUSES: { value: string; label: string; variant?: 'success' | 'warning' }[] = | ||
[ | ||
{ value: 'current', label: __( 'Active', 'jetpack' ), variant: 'warning' }, | ||
{ value: 'fixed', label: __( 'Fixed', 'jetpack' ), variant: 'success' }, | ||
{ value: 'ignored', label: __( 'Ignored', 'jetpack' ) }, | ||
]; | ||
|
||
export const THREAT_TYPES = [ | ||
{ value: 'plugin', label: __( 'Plugin', 'jetpack' ) }, | ||
{ value: 'theme', label: __( 'Theme', 'jetpack' ) }, | ||
{ value: 'core', label: __( 'WordPress', 'jetpack' ) }, | ||
{ value: 'file', label: __( 'File', 'jetpack' ) }, | ||
{ value: 'database', label: __( 'Database', 'jetpack' ) }, | ||
]; |
Oops, something went wrong.