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
568d7373
Commit
568d7373
authored
May 09, 2019
by
Andrej Ocenas
Committed by
Torkel Ödegaard
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Add Input stories (#16897)
parent
1ef15283
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
2 deletions
+69
-2
packages/grafana-ui/src/components/Input/Input.story.tsx
+40
-0
packages/grafana-ui/src/components/Input/Input.tsx
+5
-1
packages/grafana-ui/src/components/Switch/Switch.story.tsx
+22
-0
packages/grafana-ui/src/components/Switch/Switch.tsx
+1
-1
packages/grafana-ui/src/types/input.ts
+1
-0
No files found.
packages/grafana-ui/src/components/Input/Input.story.tsx
0 → 100644
View file @
568d7373
import
React
,
{
useState
}
from
'react'
;
import
{
zip
,
fromPairs
}
from
'lodash'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
Input
}
from
'./Input'
;
import
{
text
,
select
}
from
'@storybook/addon-knobs'
;
import
{
EventsWithValidation
}
from
'../../utils'
;
const
getKnobs
=
()
=>
{
return
{
validation
:
text
(
'Validation regex (will do a partial match if you do not anchor it)'
,
''
),
validationErrorMessage
:
text
(
'Validation error message'
,
'Input not valid'
),
validationEvent
:
select
(
'Validation event'
,
fromPairs
(
zip
(
Object
.
keys
(
EventsWithValidation
),
Object
.
values
(
EventsWithValidation
))),
EventsWithValidation
.
onBlur
),
};
};
const
Wrapper
=
()
=>
{
const
{
validation
,
validationErrorMessage
,
validationEvent
}
=
getKnobs
();
const
[
value
,
setValue
]
=
useState
(
''
);
const
validations
=
{
[
validationEvent
]:
[
{
rule
:
(
value
:
string
)
=>
{
return
!!
value
.
match
(
validation
);
},
errorMessage
:
validationErrorMessage
,
},
],
};
return
<
Input
value=
{
value
}
onChange=
{
e
=>
setValue
(
e
.
currentTarget
.
value
)
}
validationEvents=
{
validations
}
/>;
};
const
story
=
storiesOf
(
'UI/Input'
,
module
);
story
.
addDecorator
(
withCenteredStory
);
story
.
add
(
'input'
,
()
=>
<
Wrapper
/>);
packages/grafana-ui/src/components/Input/Input.tsx
View file @
568d7373
...
...
@@ -18,7 +18,11 @@ interface Props extends React.HTMLProps<HTMLInputElement> {
onChange
?:
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
,
status
?:
InputStatus
)
=>
void
;
}
export
class
Input
extends
PureComponent
<
Props
>
{
interface
State
{
error
:
string
|
null
;
}
export
class
Input
extends
PureComponent
<
Props
,
State
>
{
static
defaultProps
=
{
className
:
''
,
};
...
...
packages/grafana-ui/src/components/Switch/Switch.story.tsx
0 → 100644
View file @
568d7373
import
React
,
{
useState
}
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
Switch
}
from
'./Switch'
;
import
{
text
}
from
'@storybook/addon-knobs'
;
const
getKnobs
=
()
=>
{
return
{
label
:
text
(
'Label Text'
,
'Label'
),
};
};
const
SwitchWrapper
=
()
=>
{
const
{
label
}
=
getKnobs
();
const
[
checked
,
setChecked
]
=
useState
(
false
);
return
<
Switch
label=
{
label
}
checked=
{
checked
}
onChange=
{
()
=>
setChecked
(
!
checked
)
}
/>;
};
const
story
=
storiesOf
(
'UI/Switch'
,
module
);
story
.
addDecorator
(
withCenteredStory
);
story
.
add
(
'switch'
,
()
=>
<
SwitchWrapper
/>);
packages/grafana-ui/src/components/Switch/Switch.tsx
View file @
568d7373
...
...
@@ -12,7 +12,7 @@ export interface Props {
}
export
interface
State
{
id
:
any
;
id
:
string
;
}
export
class
Switch
extends
PureComponent
<
Props
,
State
>
{
...
...
packages/grafana-ui/src/types/input.ts
View file @
568d7373
...
...
@@ -4,5 +4,6 @@
}
export
interface
ValidationEvents
{
// Event name should be one of EventsWithValidation enum
[
eventName
:
string
]:
ValidationRule
[];
}
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