Skip to content

Commit 2cc9702

Browse files
committed
refactor: rename date picker component files and references from date_picker to picker across JavaScript and Django bindings.
1 parent 180c163 commit 2cc9702

15 files changed

Lines changed: 133 additions & 83 deletions

File tree

bindings/django/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ venv/
1414

1515
# JavaScript build artifacts (copied via sync)
1616
npdatetime_django/static/npdatetime_django/js/pkg/
17-
npdatetime_django/static/npdatetime_django/js/date_picker.min.js
18-
npdatetime_django/static/npdatetime_django/css/date_picker.css
17+
npdatetime_django/static/npdatetime_django/js/picker.min.js
18+
npdatetime_django/static/npdatetime_django/css/picker.css

bindings/django/DEVELOPER.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ The Django package lives in `bindings/django/` but depends on assets from `bindi
1010
npdatetime/
1111
├── bindings/
1212
│ ├── javascript/ # Source of truth for UI
13-
│ │ ├── date_picker.js # Main date picker
14-
│ │ ├── date_picker.css # Styles
13+
│ │ ├── picker.js # Main date picker
14+
│ │ ├── picker.css # Styles
1515
│ │ └── pkg/ # WASM bindings
1616
│ │
1717
│ └── django/ # Django package
1818
│ ├── build_assets.py # Asset sync script ⭐
1919
│ ├── npdatetime_django/
2020
│ │ └── static/npdatetime_django/
2121
│ │ ├── js/
22-
│ │ │ ├── date_picker.min.js # Copied from ../javascript/
22+
│ │ │ ├── picker.min.js # Copied from ../javascript/
2323
│ │ │ └── pkg/ # Copied from ../javascript/
2424
│ │ └── css/
25-
│ │ └── date_picker.css # Copied from ../javascript/
25+
│ │ └── picker.css # Copied from ../javascript/
2626
```
2727

2828
## Important: Single Source of Truth
@@ -34,8 +34,8 @@ These files are **copied** from `bindings/javascript/`. If you edit them directl
3434
### Workflow When Updating JavaScript/CSS
3535

3636
1. **Edit the source files** in `bindings/javascript/`:
37-
- `date_picker.js`
38-
- `date_picker.css`
37+
- `picker.js`
38+
- `picker.css`
3939

4040
2. **Run the build script** to sync to Django:
4141
```bash
@@ -53,8 +53,8 @@ These files are **copied** from `bindings/javascript/`. If you edit them directl
5353

5454
4. **Commit both locations** if needed:
5555
```bash
56-
git add bindings/javascript/date_picker.js
57-
git add bindings/django/npdatetime_django/static/npdatetime_django/js/date_picker.min.js
56+
git add bindings/javascript/picker.js
57+
git add bindings/django/npdatetime_django/static/npdatetime_django/js/picker.min.js
5858
git commit -m "Update date picker UI"
5959
```
6060

@@ -63,8 +63,8 @@ These files are **copied** from `bindings/javascript/`. If you edit them directl
6363
### What It Does
6464

6565
The `build_assets.py` script:
66-
- Copies `date_picker.js``static/npdatetime_django/js/date_picker.min.js`
67-
- Copies `date_picker.css``static/npdatetime_django/css/date_picker.css`
66+
- Copies `picker.js``static/npdatetime_django/js/picker.min.js`
67+
- Copies `picker.css``static/npdatetime_django/css/picker.css`
6868
- Copies `pkg/` directory → `static/npdatetime_django/js/pkg/`
6969

7070
### When to Run It
@@ -156,7 +156,7 @@ twine upload dist/*
156156
### Update JavaScript Only
157157

158158
```bash
159-
# 1. Edit bindings/javascript/date_picker.js
159+
# 1. Edit bindings/javascript/picker.js
160160
# 2. Run build script
161161
cd bindings/django
162162
python3 build_assets.py
@@ -177,7 +177,7 @@ python3 build_assets.py
177177
### Update CSS Styles
178178

179179
```bash
180-
# 1. Edit bindings/javascript/date_picker.css
180+
# 1. Edit bindings/javascript/picker.css
181181
# 2. Run build script
182182
cd bindings/django
183183
python3 build_assets.py

bindings/django/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ python build_assets.py
3434
```
3535

3636
This copies:
37-
- `date_picker.js``static/npdatetime_django/js/date_picker.min.js`
38-
- `date_picker.css``static/npdatetime_django/css/date_picker.css`
37+
- `picker.js``static/npdatetime_django/js/picker.min.js`
38+
- `picker.css``static/npdatetime_django/css/picker.css`
3939
- `pkg/``static/npdatetime_django/js/pkg/`
4040

4141
## Installation

bindings/django/WORKFLOW.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
## The Key Point
44

55
**JavaScript/CSS files have ONE source location:**
6-
- ✅ Source: `bindings/javascript/date_picker.js`
7-
- ✅ Source: `bindings/javascript/date_picker.css`
8-
- ❌ Copy: `bindings/django/npdatetime_django/static/.../date_picker.min.js`
9-
- ❌ Copy: `bindings/django/npdatetime_django/static/.../date_picker.css`
6+
- ✅ Source: `bindings/javascript/picker.js`
7+
- ✅ Source: `bindings/javascript/picker.css`
8+
- ❌ Copy: `bindings/django/npdatetime_django/static/.../picker.min.js`
9+
- ❌ Copy: `bindings/django/npdatetime_django/static/.../picker.css`
1010

1111
## Your Workflow
1212

1313
### When You Update JavaScript/CSS:
1414

1515
```bash
1616
# 1. Edit the source files
17-
vim bindings/javascript/date_picker.js
18-
vim bindings/javascript/date_picker.css
17+
vim bindings/javascript/picker.js
18+
vim bindings/javascript/picker.css
1919

2020
# 2. Sync to Django package
2121
cd bindings/django
@@ -25,7 +25,7 @@ python3 build_assets.py
2525
# Changes are automatically reflected
2626

2727
# 4. Commit (if satisfied)
28-
git add bindings/javascript/date_picker.js
28+
git add bindings/javascript/picker.js
2929
git add bindings/django/npdatetime_django/static/...
3030
git commit -m "Update date picker"
3131
```
@@ -34,8 +34,8 @@ git commit -m "Update date picker"
3434

3535
```python
3636
# Copies these files:
37-
../javascript/date_picker.js → static/.../js/date_picker.min.js
38-
../javascript/date_picker.css → static/.../css/date_picker.css
37+
../javascript/picker.js → static/.../js/picker.min.js
38+
../javascript/picker.css → static/.../css/picker.css
3939
../javascript/pkg/* → static/.../js/pkg/*
4040
```
4141

@@ -50,8 +50,8 @@ git commit -m "Update date picker"
5050

5151
| Task | Command |
5252
|------|---------|
53-
| Update JavaScript | Edit `bindings/javascript/date_picker.js` |
54-
| Update CSS | Edit `bindings/javascript/date_picker.css` |
53+
| Update JavaScript | Edit `bindings/javascript/picker.js` |
54+
| Update CSS | Edit `bindings/javascript/picker.css` |
5555
| Sync to Django | `python3 build_assets.py` |
5656
| Install for dev | `pip install -e .` |
5757
| Build package | `python setup.py sdist bdist_wheel` |

bindings/django/build_assets.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def main():
2626

2727
# Copy JavaScript files
2828
print(" Copying JavaScript files...")
29-
js_file = js_source / "date_picker.js"
29+
js_file = js_source / "picker.js"
3030
if js_file.exists():
31-
shutil.copy2(js_file, django_static / "js" / "date_picker.min.js")
32-
print(f" ✓ {js_file.name}date_picker.min.js")
31+
shutil.copy2(js_file, django_static / "js" / "picker.min.js")
32+
print(f" ✓ {js_file.name}picker.min.js")
3333
else:
3434
print(f" ⚠ Warning: {js_file} not found")
3535

3636
# Copy CSS files
3737
print(" Copying CSS files...")
38-
css_file = js_source / "date_picker.css"
38+
css_file = js_source / "picker.css"
3939
if css_file.exists():
40-
shutil.copy2(css_file, django_static / "css" / "date_picker.css")
41-
print(f" ✓ {css_file.name}date_picker.css")
40+
shutil.copy2(css_file, django_static / "css" / "picker.css")
41+
print(f" ✓ {css_file.name}picker.css")
4242
else:
4343
print(f" ⚠ Warning: {css_file} not found")
4444

@@ -56,8 +56,8 @@ def main():
5656

5757
print("\n✅ Assets built successfully!")
5858
print("\n📝 Summary:")
59-
print(" - date_picker.js → date_picker.min.js")
60-
print(" - date_picker.css → date_picker.css")
59+
print(" - picker.js → picker.min.js")
60+
print(" - picker.css → picker.css")
6161
print(" - pkg/ → js/pkg/")
6262
print("\n💡 Tip: Run 'python build_assets.py' whenever you update the JavaScript/CSS files")
6363

bindings/django/build_assets.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ mkdir -p "$DJANGO_STATIC/css"
1717

1818
# Copy JavaScript files
1919
echo " Copying JavaScript files..."
20-
cp "$JS_SOURCE/date_picker.js" "$DJANGO_STATIC/js/date_picker.min.js"
20+
cp "$JS_SOURCE/picker.js" "$DJANGO_STATIC/js/picker.min.js"
2121

2222
# Copy CSS files
2323
echo " Copying CSS files..."
24-
cp "$JS_SOURCE/date_picker.css" "$DJANGO_STATIC/css/date_picker.css"
24+
cp "$JS_SOURCE/picker.css" "$DJANGO_STATIC/css/picker.css"
2525

2626
# Copy WASM package
2727
echo " Copying WASM bindings..."
@@ -35,8 +35,8 @@ fi
3535
echo "✅ Assets built successfully!"
3636
echo ""
3737
echo "📝 Summary:"
38-
echo " - date_picker.js → date_picker.min.js"
39-
echo " - date_picker.css → date_picker.css"
38+
echo " - picker.js → picker.min.js"
39+
echo " - picker.css → picker.css"
4040
echo " - pkg/ → js/pkg/"
4141
echo ""
4242
echo "💡 Tip: Run './build_assets.sh' whenever you update the JavaScript/CSS files"

bindings/django/npdatetime_django/static/npdatetime_django/js/date_picker.min.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ export class NepaliDatePicker {
707707

708708
const dayText =
709709
this.options.language === "np" ? this.toNepaliNum(day) : day;
710-
html += `<button type="button" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="-1">${dayText}</button>`;
710+
html += `<div role="button" tabindex="0" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="-1">${dayText}</div>`;
711711
}
712712

713713
const todayBS = NepaliDate.today();
@@ -771,7 +771,7 @@ export class NepaliDatePicker {
771771
// Tithi calculation failed or feature disabled
772772
}
773773

774-
html += `<button type="button" class="${classes}" data-day="${day}" data-month-offset="0" data-details="${details}">${dayText}</button>`;
774+
html += `<div role="button" tabindex="0" class="${classes}" data-day="${day}" data-month-offset="0" data-details="${details}">${dayText}</div>`;
775775
}
776776

777777
// Next month overflow
@@ -783,7 +783,7 @@ export class NepaliDatePicker {
783783

784784
const dayText =
785785
this.options.language === "np" ? this.toNepaliNum(day) : day;
786-
html += `<button type="button" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="1">${dayText}</button>`;
786+
html += `<div role="button" tabindex="0" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="1">${dayText}</div>`;
787787
}
788788
} else {
789789
const date = new Date(this.viewDate.year, this.viewDate.month - 1, 1);
@@ -804,7 +804,7 @@ export class NepaliDatePicker {
804804
const cellIndex = startWeekday - 1 - i;
805805
const isHoliday = cellIndex % 7 === 0; // Sunday logic for AD
806806
const day = daysInPrevMonth - i;
807-
html += `<button type="button" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="-1">${day}</button>`;
807+
html += `<div role="button" tabindex="0" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="-1">${day}</div>`;
808808
}
809809

810810
const [selY, selM, selD] = this.selectedDate
@@ -863,7 +863,7 @@ export class NepaliDatePicker {
863863
if (isInRange) classes += " in-range";
864864
}
865865

866-
html += `<button type="button" class="${classes}" data-day="${day}" data-month-offset="0">${day}</button>`;
866+
html += `<div role="button" tabindex="0" class="${classes}" data-day="${day}" data-month-offset="0">${day}</div>`;
867867
}
868868

869869
// Next month overflow
@@ -872,7 +872,7 @@ export class NepaliDatePicker {
872872
for (let day = 1; day <= totalCells - currentCells; day++) {
873873
const cellIndex = currentCells + day - 1;
874874
const isHoliday = cellIndex % 7 === 0; // Sunday for AD
875-
html += `<button type="button" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="1">${day}</button>`;
875+
html += `<div role="button" tabindex="0" class="npd-day npd-overflow ${isHoliday ? "holiday" : ""}" data-day="${day}" data-month-offset="1">${day}</div>`;
876876
}
877877
}
878878

@@ -907,6 +907,14 @@ export class NepaliDatePicker {
907907
}
908908
});
909909

910+
// Keyboard accessibility for div elements
911+
btn.addEventListener("keydown", (e) => {
912+
if (e.key === "Enter" || e.key === " ") {
913+
e.preventDefault();
914+
btn.click();
915+
}
916+
});
917+
910918
// Tooltip Events
911919
this.elements.daysView
912920
.querySelectorAll(".npd-day[data-details]")
@@ -1006,7 +1014,7 @@ export class NepaliDatePicker {
10061014
const isSelected =
10071015
this.selectedDate?.year === this.viewDate.year &&
10081016
this.selectedDate?.month === index + 1;
1009-
html += `<button type="button" class="npd-month ${isSelected ? "selected" : ""}" data-month="${index + 1}">${month}</button>`;
1017+
html += `<div role="button" tabindex="0" class="npd-month ${isSelected ? "selected" : ""}" data-month="${index + 1}">${month}</div>`;
10101018
});
10111019
html += "</div>";
10121020

@@ -1019,6 +1027,14 @@ export class NepaliDatePicker {
10191027
this.viewMode = "days";
10201028
this.render();
10211029
});
1030+
1031+
// Keyboard accessibility
1032+
btn.addEventListener("keydown", (e) => {
1033+
if (e.key === "Enter" || e.key === " ") {
1034+
e.preventDefault();
1035+
btn.click();
1036+
}
1037+
});
10221038
});
10231039
}
10241040

@@ -1032,7 +1048,7 @@ export class NepaliDatePicker {
10321048
const isSelected = this.selectedDate?.year === year;
10331049
const yearText =
10341050
this.options.language === "np" ? this.toNepaliNum(year) : year;
1035-
html += `<button type="button" class="npd-year ${isSelected ? "selected" : ""}" data-year="${year}">${yearText}</button>`;
1051+
html += `<div role="button" tabindex="0" class="npd-year ${isSelected ? "selected" : ""}" data-year="${year}">${yearText}</div>`;
10361052
}
10371053
html += "</div>";
10381054

@@ -1045,6 +1061,14 @@ export class NepaliDatePicker {
10451061
this.viewMode = "months";
10461062
this.render();
10471063
});
1064+
1065+
// Keyboard accessibility
1066+
btn.addEventListener("keydown", (e) => {
1067+
if (e.key === "Enter" || e.key === " ") {
1068+
e.preventDefault();
1069+
btn.click();
1070+
}
1071+
});
10481072
});
10491073
}
10501074

bindings/django/npdatetime_django/templates/npdatetime_django/widgets/date_picker.html renamed to bindings/django/npdatetime_django/templates/npdatetime_django/widgets/picker.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% load static %}
22

3+
<link rel="stylesheet" href="{% static 'npdatetime_django/css/picker.css' %}">
4+
35
<input
46
type="{{ widget.type }}"
57
name="{{ widget.name }}"
@@ -10,7 +12,7 @@
1012
>
1113

1214
<script type="module">
13-
import { NepaliDatePicker } from '{% static "npdatetime_django/js/date_picker.min.js" %}';
15+
import { NepaliDatePicker } from '{% static "npdatetime_django/js/picker.min.js" %}';
1416

1517
document.addEventListener('DOMContentLoaded', function() {
1618
const input = document.querySelector('input[name="{{ widget.name }}"]');

bindings/django/npdatetime_django/widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class PersonForm(forms.Form):
3535
"""
3636

3737
input_type = 'text'
38-
template_name = 'npdatetime_django/widgets/date_picker.html'
38+
template_name = 'npdatetime_django/widgets/picker.html'
3939

4040
class Media:
4141
css = {
42-
'all': ('npdatetime_django/css/date_picker.css',)
42+
'all': ('npdatetime_django/css/picker.css',)
4343
}
4444
js = (
45-
'npdatetime_django/js/date_picker.min.js',
45+
'npdatetime_django/js/picker.min.js',
4646
)
4747

4848
def __init__(self, attrs=None, mode='BS', language='en', include_time=False,

0 commit comments

Comments
 (0)