Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
74013b7d
Commit
74013b7d
authored
Oct 31, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавлен WithConfirmation
parent
f2a32a90
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
1 deletions
+101
-1
WithConfirmation/i18n.po.yml
+7
-0
WithConfirmation/index.tsx
+93
-0
gettext/index.ts
+1
-1
No files found.
WithConfirmation/i18n.po.yml
0 → 100644
View file @
74013b7d
# https://git.bitmaster.ru/npm/common/tree/master/gettext#%D0%A4%D0%BE%D1%80%D0%BC%D0%B0%D1%82-poyml
-
"
"
:
locale
:
"
ru-RU"
"
Confirm
deletion"
:
"
Подтвердите
удаление"
"
Are
you
sure
you
want
to
delete
this
item?"
:
"
Вы
действительно
хотите
удалить
этот
объект?"
"
Cancel"
:
"
Отмена"
"
Confirm"
:
"
Подтвердить"
WithConfirmation/index.tsx
0 → 100644
View file @
74013b7d
import
*
as
React
from
'react'
;
import
{
Dialog
,
DialogTitle
,
DialogContent
,
DialogActions
}
from
'@material-ui/core'
;
import
{
DialogProps
}
from
'@material-ui/core/Dialog'
;
import
withStyles
,
{
WithStyles
,
StyleRules
}
from
'@material-ui/core/styles/withStyles'
;
import
{
Theme
}
from
'@material-ui/core/styles/createMuiTheme'
;
import
*
as
classNames
from
'classnames'
;
import
Button
from
'@material-ui/core/Button'
;
import
{
LocaleCtx
,
Gettext
,
withGettext
}
from
'~/gettext'
;
// Props
export
interface
Props
{
__
:
Gettext
;
ctx
:
LocaleCtx
;
className
?:
string
;
children
:
React
.
ReactNode
;
Confirmation
:
React
.
ReactType
<
ConfirmationProps
>
;
}
// State
export
interface
State
{
showConfirmation
:
boolean
;
args
:
any
[];
}
// Component
export
class
WithConfirmation
extends
React
.
Component
<
Props
&
WithStyles
,
State
>
{
state
:
State
=
{
showConfirmation
:
false
,
args
:
[]
};
handleClick
=
(...
args
)
=>
{
this
.
setState
({
args
,
showConfirmation
:
true
});
}
handleConfirm
=
()
=>
{
const
{
children
}
=
this
.
props
;
const
{
args
}
=
this
.
state
;
if
(
children
&&
children
.
hasOwnProperty
(
'props'
)
&&
typeof
(
children
[
'props'
].
onClick
)
===
'function'
)
children
[
'props'
].
onClick
.
apply
(
undefined
,
args
);
this
.
setState
({
showConfirmation
:
false
,
args
:
[]
});
};
handleCancel
=
()
=>
{
this
.
setState
({
showConfirmation
:
false
,
args
:
[]
});
};
render
()
{
const
{
__
,
ctx
,
classes
,
className
,
Confirmation
,
children
:
childrenProp
}
=
this
.
props
;
const
{
showConfirmation
}
=
this
.
state
;
const
rootClass
=
classNames
(
classes
.
root
,
className
);
const
children
=
childrenProp
&&
childrenProp
.
hasOwnProperty
(
'type'
)
?
React
.
cloneElement
(
childrenProp
as
any
,
{
onClick
:
this
.
handleClick
})
:
childrenProp
;
return
<
div
className=
{
rootClass
}
>
{
children
}
<
Confirmation
__=
{
__
}
ctx=
{
ctx
}
open=
{
showConfirmation
}
onClose=
{
this
.
handleCancel
}
onConfirm=
{
this
.
handleConfirm
}
/>
</
div
>;
}
}
export
default
withStyles
(
styles
)(
withGettext
(
require
(
'./i18n.po.yml'
))(
WithConfirmation
));
// Props
export
type
ConfirmationProps
=
DialogProps
&
{
__
:
Gettext
;
onConfirm
?();
}
// Component
export
const
DeleteConfirmation
=
withStyles
(
styles
)((
props
:
ConfirmationProps
&
WithStyles
)
=>
{
const
{
__
,
classes
,
onConfirm
,
...
other
}
=
props
;
return
(
<
Dialog
{
...
other
}
>
<
DialogTitle
>
{
__
(
'Confirm deletion'
)
}
</
DialogTitle
>
<
DialogContent
>
{
__
(
'Are you sure you want to delete this item?'
)
}
</
DialogContent
>
<
DialogActions
>
<
Button
onClick=
{
other
.
onClose
}
>
{
__
(
'Cancel'
)
}
</
Button
>
<
Button
onClick=
{
onConfirm
}
color=
"primary"
>
{
__
(
'Confirm'
)
}
</
Button
>
</
DialogActions
>
</
Dialog
>
);
});
// Styles
export
function
styles
(
theme
:
Theme
):
StyleRules
{
return
{
};
}
gettext/index.ts
View file @
74013b7d
...
@@ -89,7 +89,7 @@ export function withGettext(...webpackContexts) {
...
@@ -89,7 +89,7 @@ export function withGettext(...webpackContexts) {
}
}
}
}
// @ts-ignore
// @ts-ignore
WithTranslations
.
n
ame
=
'WithTranslations('
+
Component
.
name
+
')'
;
WithTranslations
.
displayN
ame
=
'WithTranslations('
+
Component
.
name
+
')'
;
return
WithTranslations
;
return
WithTranslations
;
};
};
}
}
...
...
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