Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
d8167ffb
Commit
d8167ffb
authored
Mar 19, 2019
by
Andrej Ocenas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SecretFormField component
parent
0d84a3fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
1 deletions
+96
-1
packages/grafana-ui/src/components/SecretFormFied/SecretFormField.story.tsx
+38
-0
packages/grafana-ui/src/components/SecretFormFied/SecretFormField.tsx
+56
-0
packages/grafana-ui/src/components/index.ts
+1
-0
packages/grafana-ui/src/utils/storybook/UseState.tsx
+1
-1
No files found.
packages/grafana-ui/src/components/SecretFormFied/SecretFormField.story.tsx
0 → 100644
View file @
d8167ffb
import
React
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
boolean
}
from
'@storybook/addon-knobs'
;
import
{
SecretFormField
}
from
'./SecretFormField'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
UseState
}
from
'../../utils/storybook/UseState'
;
const
SecretFormFieldStories
=
storiesOf
(
'UI/SecretFormField/SecretFormField'
,
module
);
SecretFormFieldStories
.
addDecorator
(
withCenteredStory
);
const
getSecretFormFieldKnobs
=
()
=>
{
return
{
isConfigured
:
boolean
(
'Set configured state'
,
false
),
};
};
SecretFormFieldStories
.
add
(
'default'
,
()
=>
{
const
knobs
=
getSecretFormFieldKnobs
();
return
(
<
UseState
initialState=
"Input value"
>
{
(
value
,
setValue
)
=>
(
<
SecretFormField
label=
{
'Secret field'
}
labelWidth=
{
10
}
value=
{
value
}
isConfigured=
{
knobs
.
isConfigured
}
onChange=
{
e
=>
setValue
(
e
.
currentTarget
.
value
)
}
onReset=
{
()
=>
{
action
(
'Value was reset'
)(
''
);
setValue
(
''
);
}
}
/>
)
}
</
UseState
>
);
});
packages/grafana-ui/src/components/SecretFormFied/SecretFormField.tsx
0 → 100644
View file @
d8167ffb
import
{
omit
}
from
'lodash'
;
import
React
,
{
InputHTMLAttributes
,
FunctionComponent
}
from
'react'
;
import
{
FormField
}
from
'..'
;
interface
Props
extends
InputHTMLAttributes
<
HTMLInputElement
>
{
onReset
:
()
=>
void
;
isConfigured
:
boolean
;
label
?:
string
;
labelWidth
?:
number
;
inputWidth
?:
number
;
}
export
const
SecretFormField
:
FunctionComponent
<
Props
>
=
({
label
,
labelWidth
,
inputWidth
,
onReset
,
isConfigured
,
...
inputProps
}:
Props
)
=>
{
return
(
<
FormField
label=
{
label
||
'Password'
}
labelWidth=
{
labelWidth
}
inputEl=
{
isConfigured
?
(
<>
<
input
type=
"text"
className=
{
`gf-form-input width-${inputWidth! - 2}`
}
disabled=
{
true
}
value=
"configured"
{
...
omit
(
inputProps
,
'
value
')}
/>
<
button
className=
"btn btn-secondary gf-form-btn"
onClick=
{
onReset
}
>
reset
</
button
>
</>
)
:
(
<
input
type=
"password"
className=
{
`gf-form-input width-${inputWidth}`
}
placeholder=
{
'password'
}
{
...
inputProps
}
/>
)
}
/>
);
};
SecretFormField
.
defaultProps
=
{
inputWidth
:
12
,
};
SecretFormField
.
displayName
=
'SecretFormField'
;
packages/grafana-ui/src/components/index.ts
View file @
d8167ffb
...
...
@@ -14,6 +14,7 @@ export { default as resetSelectStyles } from './Select/resetSelectStyles';
// Forms
export
{
FormLabel
}
from
'./FormLabel/FormLabel'
;
export
{
FormField
}
from
'./FormField/FormField'
;
export
{
SecretFormField
}
from
'./SecretFormFied/SecretFormField'
;
export
{
LoadingPlaceholder
}
from
'./LoadingPlaceholder/LoadingPlaceholder'
;
export
{
ColorPicker
,
SeriesColorPicker
}
from
'./ColorPicker/ColorPicker'
;
...
...
packages/grafana-ui/src/utils/storybook/UseState.tsx
View file @
d8167ffb
...
...
@@ -2,7 +2,7 @@ import React from 'react';
interface
StateHolderProps
<
T
>
{
initialState
:
T
;
children
:
(
currentState
:
T
,
updateState
:
(
nextState
:
T
)
=>
void
)
=>
JSX
.
Element
;
children
:
(
currentState
:
T
,
updateState
:
(
nextState
:
T
)
=>
void
)
=>
React
.
ReactNode
;
}
export
class
UseState
<
T
>
extends
React
.
Component
<
StateHolderProps
<
T
>
,
{
value
:
T
;
initialState
:
T
}
>
{
...
...
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