Example #1
0
 def ListItem(props):
     return el(
         'li',
         None,
         el(
             'button', {
                 'type': 'button',
                 'onClick': lambda: handleDelete(props['item']),
                 'style': {
                     'color': 'darkred',
                     'marginRight': '5px',
                     'width': '60px'
                 }
             }, "Delete"),
         el(
             'button', {
                 'type': 'button',
                 'onClick': lambda: handleEdit(props['item']),
                 'style': {
                     'color': 'blue',
                     'marginRight': '5px',
                     'width': '60px'
                 }
             }, "Edit"),
         props['item'],
     )
Example #2
0
 def ListItem(props):
     task = props['task']
     if taskFilter == "all" or \
             (taskFilter == "open" and not task['status']) or \
             (taskFilter == "closed" and task['status']):
         return el(
             'li',
             None,
             task['name'] + " ",
             el('button', {
                 'type': 'button',
                 'onClick': lambda: handleDelete(task)
             }, "Delete"),
             el('button', {
                 'type': 'button',
                 'onClick': lambda: handleEdit(task)
             }, "Edit"),
             el('label', {'htmlFor': 'status'}, " Completed:"),
             el(
                 'input', {
                     'type': 'checkbox',
                     'id': 'status',
                     'onChange': lambda e: handleChangeStatus(e, task),
                     'checked': task['status']
                 }),
         )
     else:
         return None
Example #3
0
def App():
    newItem, setNewItem = useState("")
    listItems, setListItems = useState([])

    def handleSubmit():
        new_list = list(listItems)  # Make a copy
        new_list.append(newItem)  # Add the new item
        setListItems(new_list)  # Update our state
        setNewItem("")  # Clear the new item value

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    def getListItems():
        items = []
        for item in listItems:
            element = el('li', {'key': item}, item)
            items.append(element)

        return items

    return el(
        'div',
        None,
        el('label', {'htmlFor': 'editBox'}, "New Item: "),
        el('input', {
            'id': 'editBox',
            'onChange': handleChange,
            'value': newItem
        }),
        el('button', {'onClick': handleSubmit}, "Submit"),
        el('ol', None, getListItems()),
    )
Example #4
0
def Component5(props):
    ctx = useContext(Ctx)
    testVal = ctx['testVal']
    return el(Box, None,
              el(ROTextField, {'label': 'Copy From Row 1',
                              'value': testVal}
                ),
             )
Example #5
0
 def ListItem(props):
     return el(
         'li',
         None,
         props['item'] + " ",
         el('button', {
             'type': 'button',
             'onClick': lambda: handleDelete(props['item'])
         }, "Delete"),
     )
Example #6
0
def App():
    testVal, setTestVal = useState("")

    def handleChange(event):
        target = event['target']
        setTestVal(target['value'])

    return el(Box, {'key': 'App', 'style': {'width': '200px'}},
              el(TextField, {'label': 'Row 1',
                             'value': testVal,
                             'onChange': handleChange}
                ),
              el(Component2, {'testVal1': testVal})
             )
Example #7
0
 def ListItems():
     return [
         el(ListItem, {
             'key': item,
             'item': item
         }) for item in listItems
     ]
Example #8
0
    def ListItems():
        items = []
        for item in listItems:
            element = el('li', {'key': item}, item)
            items.append(element)

        return items
Example #9
0
 def ListItems():
     return [
         el(ListItem, {
             'key': task['name'],
             'task': task
         }) for task in taskList
     ]
Example #10
0
 def ListItem(props):
     return el('li', {'className': 'list-group-item p-1'},
               el('button',
                  {'onClick': lambda: handleDelete(props['item']),
                   'className': 'btn btn-danger btn-sm mr-2'
                  },
                  "Delete"
                 ),
               el('button',
                  {'onClick': lambda: handleEdit(props['item']),
                   'className': 'btn btn-primary btn-sm mr-2'
                  },
                  "Edit"
                 ),
               props['item'],
              )
Example #11
0
 def Button(props):
     new_props = {'type': 'button'}
     new_props.update(props)
     new_style = new_props.pop('style', {})
     new_style.update({'marginRight': '5px', 'width': '60px'})
     new_props.update({'style': new_style})
     return el('button', new_props)
Example #12
0
def ListItem(props):
    item = props['item']
    handleDelete = props['handleDelete']
    handleEdit = props['handleEdit']

    return el(
        'li',
        None,
        props['item'] + " ",
        el('button', {
            'type': 'button',
            'onClick': lambda: handleDelete(item)
        }, "Delete"),
        el('button', {
            'type': 'button',
            'onClick': lambda: handleEdit(item)
        }, "Edit"),
    )
Example #13
0
 def ListItem(props):
     return el(
         'li',
         None,
         el(
             'button', {
                 'type': 'button',
                 'onClick': lambda: handleDelete(props['item']),
                 'className': 'deleteBtn'
             }, "Delete"),
         el(
             'button', {
                 'type': 'button',
                 'onClick': lambda: handleEdit(props['item']),
                 'className': 'editBtn'
             }, "Edit"),
         props['item'],
     )
Example #14
0
def ListItems(props):
    return [
        el(
            ListItem, {
                'key': item,
                'item': item,
                'handleDelete': props['handleDelete'],
                'handleEdit': props['handleEdit']
            }) for item in props['listItems']
    ]
Example #15
0
File: app.py Project: rtp-book/code
def StyledTextField(props):
    new_props = {'type': 'text',
                 'fullWidth': True,
                 'variant': 'outlined',
                 'InputLabelProps': {'shrink': True},
                 'InputProps': {'margin': 'dense'},
                 'margin': 'dense',
                }

    new_props.update(props)
    return el(TextField, new_props)
Example #16
0
 def ListItem(props):
     return el(
         'li',
         None,
         el(
             Button, {
                 'onClick': lambda: handleDelete(props['item']),
                 'style': {
                     'color': 'darkred'
                 }
             }, "Delete"),
         el(
             Button, {
                 'onClick': lambda: handleEdit(props['item']),
                 'style': {
                     'color': 'blue'
                 }
             }, "Edit"),
         props['item'],
     )
Example #17
0
def ROTextField(props):
    new_props = {'fullWidth': True,
                 'variant': 'outlined',
                 'InputLabelProps': {'shrink': True},
                 'InputProps': {'margin': 'dense'},
                 'margin': 'dense',
                 'disabled': True
                }

    new_props.update(props)
    return el(TextField, new_props)
Example #18
0
    def ItemVu(props):
        item = props['item']
        current_theme = useTheme()
        specialColor = current_theme['palette']['special']['main']
        button_style = {'margin': '0 0.5rem 0 0'}

        return el(ListItem, {'dense': True},
                  el(Button,
                     {'color': 'secondary',
                      'style': button_style,
                      'onClick': lambda: handleDelete(item)
                     },
                     el('span', {'className': 'material-icons'}, 'delete'),
                     "Delete"
                    ),
                  el(Button,
                     {'color': 'primary',
                      'style': button_style,
                      'onClick': lambda: handleEdit(item)
                     },
                     el('span', {'className': 'material-icons'}, 'edit'),
                     "Edit"
                    ),
                  el(Typography, {'style': {'color': specialColor}}, item)
                 )
Example #19
0
 def ItemVu(props):
     return el(ListItem, {'dense': True},
               el(Button,
                  {'variant': 'contained',
                   'color': 'secondary',
                   'size': 'small',
                   'style': {'marginRight': '0.5rem'},
                   'onClick': lambda: handleDelete(props['item']),
                  },
                  "Delete"
                 ),
               el(Button,
                  {'variant': 'contained',
                   'color': 'primary',
                   'size': 'small',
                   'style': {'marginRight': '0.5rem'},
                   'onClick': lambda: handleEdit(props['item']),
                  },
                  "Edit"
                 ),
               el(Typography, {'variant': 'body1'}, props['item'])
              )
Example #20
0
File: app.py Project: rtp-book/code
def App():
    newItem, setNewItem = useState("")

    def handleSubmit():
        alert(f"Item is : {newItem}")
        setNewItem("")

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    return el(
        'div',
        None,
        el('label', {'htmlFor': 'editBox'}, "New Item: "),
        el('input', {
            'id': 'editBox',
            'onChange': handleChange,
            'value': newItem
        }),
        el('button', {'onClick': handleSubmit}, "Submit"),
    )
Example #21
0
def App():
    newItem, setNewItem = useState("")
    listItems, setListItems = useState([])

    def handleSubmit(event):
        event.preventDefault()
        new_list = list(listItems)  # Make a copy
        new_list.append(newItem)  # Add the new item
        setListItems(new_list)  # Update our state
        setNewItem("")  # Clear the new item value

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    def handleDelete(item):
        new_list = list(listItems)  # Make a copy
        new_list.remove(item)  # Remove the specified item
        setListItems(new_list)  # Update our state

    def ListItem(props):
        return el(
            'li',
            None,
            props['item'] + " ",
            el('button', {
                'type': 'button',
                'onClick': lambda: handleDelete(props['item'])
            }, "Delete"),
        )

    def ListItems():
        items = []
        for item in listItems:
            items.append(el(ListItem, {'key': item, 'item': item}))
        return items

    return el(
        'form',
        {'onSubmit': handleSubmit},
        el('label', {'htmlFor': 'editBox'}, "New Item: "),
        el('input', {
            'id': 'editBox',
            'onChange': handleChange,
            'value': newItem
        }),
        el('input', {'type': 'submit'}),
        el('ol', None, el(ListItems, None)),
    )
Example #22
0
File: app.py Project: rtp-book/code
def App():
    newItem, setNewItem = useState("")
    editItem, setEditItem = useState("")
    listItems, setListItems = useState([])

    def handleSubmit(event):
        event.preventDefault()
        new_list = list(listItems)  # Make a copy
        if len(editItem) > 0:  # In edit mode
            new_list[new_list.index(editItem)] = newItem
        else:  # In add mode
            new_list.append(newItem)  # Add the new item
        setListItems(new_list)  # Update our state
        setNewItem("")  # Clear the new item value
        setEditItem("")  # Clear the edit item value

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    def handleDelete(item):
        new_list = list(listItems)  # Make a copy
        new_list.remove(item)  # Remove the specified item
        setListItems(new_list)  # Update our state

    def handleEdit(item):
        setNewItem(item)  # Set the new item value
        setEditItem(item)  # Set the edit item value

    return el('form', {'onSubmit': handleSubmit},
              el('label', {'htmlFor': 'editBox'},
                 "Add Item: " if len(editItem) == 0 else "Edit Item: "
                ),
              el('input', {'id': 'editBox',
                           'onChange': handleChange,
                           'value': newItem
                          }
                ),
              el('input', {'type': 'submit'}),
              el('ol', None,
                 el(ListItems, {'listItems': listItems,
                                'handleDelete': handleDelete,
                                'handleEdit': handleEdit}
                   )
                ),
             )
Example #23
0
    def ItemVu(props):
        item = props['item']
        theme = useTheme()
        specialColor = theme['palette']['special']['main']
        classes = useStyle({'bgcolor': specialColor})

        return el(
            ListItem, {'dense': True},
            el(
                Button, {
                    'color': 'secondary',
                    'className': classes.root,
                    'onClick': lambda: handleDelete(item)
                }, el('span', {'className': 'material-icons'}, 'delete'),
                "Delete"),
            el(StyledButton, {
                'color': 'primary',
                'onClick': lambda: handleEdit(item)
            }, el('span', {'className': 'material-icons'}, 'edit'), "Edit"),
            el(Typography, {'style': {
                'color': specialColor
            }}, item))
Example #24
0
def Component4(props):
    return el(Box, None,
              el(ROTextField, {'label': 'Row 4', 'value': 'Row Four'}),
              el(Component5, None)
             )
Example #25
0
def Component3(props):
    return el(Box, None,
              el(ROTextField, {'label': 'Row 3', 'value': 'Row Three'}),
              el(Component4, None)
             )
Example #26
0
def Component2(props):
    return el(Box, None,
              el(ROTextField, {'label': 'Row 2', 'value': 'Row Two'}),
              el(Component3, None)
             )
Example #27
0
def App():
    newTask, setNewTask = useState("")
    editTask, setEditTask = useState(None)
    taskList, setTaskList = useState([])
    taskCount, setTaskCount = useState(0)
    taskFilter, setTaskFilter = useState("all")

    def handleSubmit(event):
        event.preventDefault()
        new_list = list(taskList)  # Make a copy
        if editTask is not None:  # In edit mode
            taskIndex = new_list.index(editTask)  # Get list position
            new_list[taskIndex].update({'name': newTask})  # Update name
        else:  # In add mode
            new_list.append({'name': newTask, 'status': False})  # Add new item
        setTaskList(new_list)  # Update our state
        setNewTask("")  # Clear the new item value
        setEditTask(None)  # Clear the edit item value

    def handleEdit(task):
        setNewTask(task['name'])  # Set the new item value
        setEditTask(task)  # Set the edit item value

    def handleDelete(task):
        new_list = list(taskList)  # Make a copy
        new_list.remove(task)  # Remove the specified item
        setTaskList(new_list)  # Update our state

    def handleChange(event):
        target = event['target']
        if target['name'] == 'taskFilter':
            setTaskFilter(target['value'])
        else:
            setNewTask(target['value'])

    def handleChangeStatus(event, task):
        target = event['target']
        new_list = list(taskList)  # Make a copy
        taskIndex = new_list.index(task)  # Get list position
        new_list[taskIndex].update({'status': target['checked']})  # Update
        setTaskList(new_list)  # Update our state

    def ListItem(props):
        task = props['task']
        if taskFilter == "all" or \
                (taskFilter == "open" and not task['status']) or \
                (taskFilter == "closed" and task['status']):
            return el(
                'li',
                None,
                task['name'] + " ",
                el('button', {
                    'type': 'button',
                    'onClick': lambda: handleDelete(task)
                }, "Delete"),
                el('button', {
                    'type': 'button',
                    'onClick': lambda: handleEdit(task)
                }, "Edit"),
                el('label', {'htmlFor': 'status'}, " Completed:"),
                el(
                    'input', {
                        'type': 'checkbox',
                        'id': 'status',
                        'onChange': lambda e: handleChangeStatus(e, task),
                        'checked': task['status']
                    }),
            )
        else:
            return None

    def ListItems():
        return [
            el(ListItem, {
                'key': task['name'],
                'task': task
            }) for task in taskList
        ]

    def updateCount():
        if taskFilter == 'open':
            new_list = [task for task in taskList if not task['status']]
        elif taskFilter == 'closed':
            new_list = [task for task in taskList if task['status']]
        else:
            new_list = [task for task in taskList]

        setTaskCount(len(new_list))

    useEffect(lambda: setTitle("ToDo List"), [])
    useEffect(updateCount, [taskList, taskFilter])

    return el(
        'form',
        {'onSubmit': handleSubmit},
        el('div', None, f"Number of Tasks: {taskCount}"),
        el(
            'div',
            None,
            el('label', {'htmlFor': 'all'}, "All Tasks:"),
            el(
                'input', {
                    'type': 'radio',
                    'name': 'taskFilter',
                    'id': 'all',
                    'value': 'all',
                    'onChange': handleChange,
                    'checked': taskFilter == 'all'
                }),
            el('label', {'htmlFor': 'open'}, " Active:"),
            el(
                'input', {
                    'type': 'radio',
                    'name': 'taskFilter',
                    'id': 'open',
                    'value': 'open',
                    'onChange': handleChange,
                    'checked': taskFilter == 'open'
                }),
            el('label', {'htmlFor': 'closed'}, " Completed:"),
            el(
                'input', {
                    'type': 'radio',
                    'name': 'taskFilter',
                    'id': 'closed',
                    'value': 'closed',
                    'onChange': handleChange,
                    'checked': taskFilter == 'closed'
                }),
        ),
        el('label', {'htmlFor': 'editBox'},
           "Edit Task: " if editTask is not None else "Add Task: "),
        el('input', {
            'id': 'editBox',
            'onChange': handleChange,
            'value': newTask
        }),
        el('input', {'type': 'submit'}),
        el('ol', None, el(ListItems, None)),
    )
Example #28
0
def App():
    newItem, setNewItem = useState("")
    editItem, setEditItem = useState("")
    listItems, setListItems = useState([])

    def handleSubmit(event):
        event.preventDefault()
        new_list = list(listItems)  # Make a copy
        if len(editItem) > 0:  # In edit mode
            new_list[new_list.index(editItem)] = newItem
        else:  # In add mode
            new_list.append(newItem)  # Add the new item
        setListItems(new_list)  # Update our state
        setNewItem("")  # Clear the new item value
        setEditItem("")  # Clear the edit item value

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    def handleDelete(item):
        new_list = list(listItems)  # Make a copy
        new_list.remove(item)  # Remove the specified item
        setListItems(new_list)  # Update our state

    def handleEdit(item):
        setNewItem(item)  # Set the new item value
        setEditItem(item)  # Set the edit item value

    def ListItem(props):
        return el(
            'li',
            None,
            el(
                'button', {
                    'type': 'button',
                    'onClick': lambda: handleDelete(props['item']),
                    'className': 'deleteBtn'
                }, "Delete"),
            el(
                'button', {
                    'type': 'button',
                    'onClick': lambda: handleEdit(props['item']),
                    'className': 'editBtn'
                }, "Edit"),
            props['item'],
        )

    def ListItems():
        return [
            el(ListItem, {
                'key': item,
                'item': item
            }) for item in listItems
        ]

    return el(
        'form',
        {'onSubmit': handleSubmit},
        el(
            'label', {
                'htmlFor': 'editBox',
                'className': 'adding' if len(editItem) == 0 else 'editing'
            }, "Add Item: " if len(editItem) == 0 else "Edit Item: "),
        el('input', {
            'id': 'editBox',
            'onChange': handleChange,
            'value': newItem
        }),
        el('input', {
            'type': 'submit',
            'className': 'submitBtn'
        }),
        el('ol', None, el(ListItems, None)),
    )
Example #29
0
def App():
    newItem, setNewItem = useState("")
    editItem, setEditItem = useState("")
    listItems, setListItems = useState([])

    def handleSubmit(event):
        event.preventDefault()
        new_list = list(listItems)  # Make a copy
        if len(editItem) > 0:  # In edit mode
            new_list[new_list.index(editItem)] = newItem
        else:  # In add mode
            new_list.append(newItem)  # Add the new item
        setListItems(new_list)  # Update our state
        setNewItem("")  # Clear the new item value
        setEditItem("")  # Clear the edit item value

    def handleChange(event):
        target = event['target']
        setNewItem(target['value'])

    def handleDelete(item):
        new_list = list(listItems)  # Make a copy
        new_list.remove(item)  # Remove the specified item
        setListItems(new_list)  # Update our state

    def handleEdit(item):
        setNewItem(item)  # Set the new item value
        setEditItem(item)  # Set the edit item value

    def ItemVu(props):
        item = props['item']
        theme = useTheme()
        specialColor = theme['palette']['special']['main']
        classes = useStyle({'bgcolor': specialColor})

        return el(
            ListItem, {'dense': True},
            el(
                Button, {
                    'color': 'secondary',
                    'className': classes.root,
                    'onClick': lambda: handleDelete(item)
                }, el('span', {'className': 'material-icons'}, 'delete'),
                "Delete"),
            el(StyledButton, {
                'color': 'primary',
                'onClick': lambda: handleEdit(item)
            }, el('span', {'className': 'material-icons'}, 'edit'), "Edit"),
            el(Typography, {'style': {
                'color': specialColor
            }}, item))

    def ListItemsVu():
        return [el(ItemVu, {'key': item, 'item': item}) for item in listItems]

    if len(editItem) == 0:
        editColor = 'secondary'
        editLabel = "Add Item:"
    else:
        editColor = 'primary'
        editLabel = "Edit Item:"

    return el(
        ThemeProvider, {'theme': theme},
        el(
            Container, {'maxWidth': 'sm'},
            el(
                AppBar, {
                    'position': 'static',
                    'style': {
                        'marginBottom': '0.5rem'
                    }
                },
                el(Box, {
                    'width': '100%',
                    'marginLeft': '0.5rem'
                }, el(Typography, {'variant': 'h6'}, "React to Python"))),
            el(
                Paper,
                {'elevation': 2},
                el(
                    'form',
                    {
                        'onSubmit': handleSubmit,
                        'style': {
                            'marginLeft': '1rem'
                        }
                    },
                    el(
                        TextField, {
                            'InputLabelProps': {
                                'color': editColor
                            },
                            'label': editLabel,
                            'value': newItem,
                            'onChange': handleChange,
                            'autoFocus': True
                        }),
                    el(Button, {
                        'type': 'submit',
                        'size': 'medium'
                    }, "Submit"),
                ),
                el(List, None, el(ListItemsVu, None)),
            )))
Example #30
0
 def ListItemsVu():
     return [el(ItemVu, {'key': item, 'item': item}) for item in listItems]