Skip to content

Commit 8b2fba1

Browse files
committed
test antd datepicker
1 parent 5964334 commit 8b2fba1

14 files changed

+228
-56
lines changed

R/antdCascader.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#'
55
#' @inheritParams shiny::textInput
66
#' @param options Specify the options the user can select from.
7-
#' @param isDisabled Disable the control.
87
#'
98
#' @importFrom reactR createReactShinyInput
109
#' @importFrom htmltools htmlDependency tags validateCssUnit
@@ -23,11 +22,11 @@ antdCascaderInput <- function(inputId,
2322
inputId = inputId,
2423
class = "antdCascader",
2524
dependencies = htmlDependency(
26-
name = "antd-cascader-input",
25+
name = "antd-input",
2726
version = "1.0.0",
28-
src = "www/reactwidgets/antdCascader",
27+
src = "www/reactwidgets/antd",
2928
package = "reactwidgets",
30-
script = "antdCascader.js"
29+
script = "antd.js"
3130
),
3231
default = if (is.null(selected)) list() else list1(selected),
3332
configuration = list(

R/antdDatePicker.R

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#' Ant Design Date Picker
2+
#'
3+
#' Cascade selection box.
4+
#'
5+
#' @inheritParams shiny::textInput
6+
#' @param options Specify the options the user can select from.
7+
#'
8+
#' @importFrom reactR createReactShinyInput
9+
#' @importFrom htmltools htmlDependency tags validateCssUnit
10+
#'
11+
#' @noRd
12+
antdDatePickerInput <- function(inputId,
13+
label,
14+
value = NULL,
15+
...,
16+
className = "d-block w-100",
17+
width = 500) {
18+
createReactShinyInput(
19+
inputId = inputId,
20+
class = "antdDatePicker",
21+
dependencies = htmlDependency(
22+
name = "antd-input",
23+
version = "1.0.0",
24+
src = "www/reactwidgets/antd",
25+
package = "reactwidgets",
26+
script = "antd.js"
27+
),
28+
default = if (is.null(value)) list() else list1(value),
29+
configuration = list(
30+
options = options,
31+
props = list(
32+
className = className,
33+
...
34+
),
35+
width = validateCssUnit(width),
36+
label = makeLabel(label, inputId)
37+
),
38+
container = tags$div
39+
)
40+
}
41+
42+
43+
44+
#' Ant Design Date Picker
45+
#'
46+
#' Cascade selection box.
47+
#'
48+
#' @inheritParams shiny::textInput
49+
#' @param options Specify the options the user can select from.
50+
#'
51+
#' @importFrom reactR createReactShinyInput
52+
#' @importFrom htmltools htmlDependency tags validateCssUnit
53+
#'
54+
#' @noRd
55+
antdDateRangePickerInput <- function(inputId,
56+
label,
57+
value = NULL,
58+
...,
59+
className = "w-100",
60+
width = 500) {
61+
createReactShinyInput(
62+
inputId = inputId,
63+
class = "antdDateRangePicker",
64+
dependencies = htmlDependency(
65+
name = "antd-input",
66+
version = "1.0.0",
67+
src = "www/reactwidgets/antd",
68+
package = "reactwidgets",
69+
script = "antd.js"
70+
),
71+
default = if (is.null(value)) list() else list1(value),
72+
configuration = list(
73+
options = options,
74+
props = list(
75+
defaultValue = value,
76+
className = className,
77+
...
78+
),
79+
width = validateCssUnit(width),
80+
label = makeLabel(label, inputId)
81+
),
82+
container = tags$div
83+
)
84+
}
85+

examples/antdDatePicker.R

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
library(shiny)
2+
library(bslib)
3+
# library(reactwidgets)
4+
pkgload::load_all()
5+
6+
ui <- page_fluid(
7+
titlePanel("antdDatePickerInput Example"),
8+
fluidRow(
9+
column(
10+
width = 6,
11+
antdDatePickerInput(
12+
"ID1",
13+
label = "Basic Date Picker example:",
14+
value = Sys.Date(),
15+
# format = "YYYY-MM-DD",
16+
# selected = "marseille",
17+
width = "100%"
18+
),
19+
verbatimTextOutput("res1")
20+
),
21+
column(
22+
width = 6,
23+
antdDateRangePickerInput(
24+
"ID2",
25+
label = "Range Date Picker example:",
26+
width = "100%"
27+
),
28+
verbatimTextOutput("res2")
29+
)
30+
)
31+
)
32+
33+
server <- function(input, output, session) {
34+
output$res1 <- renderPrint({
35+
input$ID1
36+
})
37+
output$res2 <- renderPrint({
38+
input$ID2
39+
})
40+
}
41+
42+
if (interactive())
43+
shinyApp(ui, server)

inst/www/reactwidgets/antd/antd.js

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/reactwidgets/antd/antd.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/reactwidgets/antdCascader/antdCascader.js

-18
This file was deleted.

inst/www/reactwidgets/antdCascader/antdCascader.js.map

-1
This file was deleted.

inst/www/reactwidgets/dualListBox/dualListBox.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/reactwidgets/dualListBox/dualListBox.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/reactwidgets/reactSelect/reactSelect.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/reactwidgets/reactSelect/reactSelect.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/antd.jsx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { reactShinyInput } from "reactR";
2+
import React, { useState } from "react";
3+
import { Cascader, DatePicker } from "antd";
4+
import dayjs from 'dayjs';
5+
import LabelInput from "./LabelInput";
6+
7+
8+
const CascaderInput = ({ configuration, value, setValue }) => {
9+
function onChange(newValue) {
10+
setValue(newValue)
11+
}
12+
return (
13+
<div class="form-group shiny-input-container" style={{width: configuration.width}}>
14+
<LabelInput
15+
config={configuration.label}
16+
/>
17+
<Cascader
18+
options={configuration.options}
19+
onChange={onChange}
20+
{...configuration.props}
21+
/>
22+
</div>
23+
);
24+
};
25+
26+
reactShinyInput(".antdCascader", "reactwidgets.antdCascader", CascaderInput);
27+
28+
29+
30+
31+
const DatePickerInput = ({ configuration, value, setValue }) => {
32+
function onChange(date, dateString) {
33+
setValue(dateString)
34+
}
35+
return (
36+
<div class="form-group shiny-input-container" style={{width: configuration.width}}>
37+
<LabelInput
38+
config={configuration.label}
39+
/>
40+
<DatePicker
41+
defaultValue={dayjs(value[0], "YYYY-MM-DD")}
42+
onChange={onChange}
43+
{...configuration.props}
44+
/>
45+
</div>
46+
);
47+
};
48+
49+
reactShinyInput(".antdDatePicker", "reactwidgets.antdDatePicker", DatePickerInput);
50+
51+
52+
53+
const DateRangePickerInput = ({ configuration, value, setValue }) => {
54+
const { RangePicker } = DatePicker;
55+
function onChange(date, dateString) {
56+
setValue(dateString)
57+
}
58+
return (
59+
<div class="form-group shiny-input-container" style={{width: configuration.width}}>
60+
<LabelInput
61+
config={configuration.label}
62+
/>
63+
<RangePicker
64+
onChange={onChange}
65+
{...configuration.props}
66+
/>
67+
</div>
68+
);
69+
};
70+
71+
reactShinyInput(".antdDateRangePicker", "reactwidgets.antdDateRangePicker", DateRangePickerInput);

srcjs/antdCascader.jsx

-26
This file was deleted.

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
entry: {
55
"dualListBox/dualListBox": path.join(__dirname, 'srcjs', 'dualListBox.jsx'),
66
"reactSelect/reactSelect": path.join(__dirname, 'srcjs', 'reactSelect.jsx'),
7-
"antdCascader/antdCascader": path.join(__dirname, 'srcjs', 'antdCascader.jsx')
7+
"antd/antd": path.join(__dirname, 'srcjs', 'antd.jsx')
88
},
99
output: {
1010
path: path.join(__dirname, 'inst/www/reactwidgets'),

0 commit comments

Comments
 (0)