simple-question-react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -0
- package/dist/index.cjs.js +125 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.esm.js +119 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# simple-question-react
|
|
2
|
+
|
|
3
|
+
Basit ve özelleştirilebilir questionnaire (anket) component'i - React için.
|
|
4
|
+
|
|
5
|
+
## Özellikler
|
|
6
|
+
|
|
7
|
+
- 🎯 **Basit Kullanım** - Minimal API ile hızlı entegrasyon
|
|
8
|
+
- 📝 **TypeScript** - Full type safety ve IntelliSense desteği
|
|
9
|
+
- 🎨 **Özelleştirilebilir** - CSS Custom Properties ile tema desteği
|
|
10
|
+
- 🌙 **Dark Mode** - Otomatik sistem tercihi desteği
|
|
11
|
+
- ♿ **Accessibility** - ARIA attributes ve keyboard navigation
|
|
12
|
+
- 📦 **Tree-shakeable** - Sadece kullandığın kadar bundle
|
|
13
|
+
|
|
14
|
+
## Kurulum
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install simple-question-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Kullanım
|
|
21
|
+
|
|
22
|
+
### Temel Kullanım
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { SimpleQuestion } from 'simple-question-react';
|
|
26
|
+
import 'simple-question-react/styles.css';
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
const handleSubmit = (choice) => {
|
|
30
|
+
console.log('Seçilen:', choice);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<SimpleQuestion
|
|
35
|
+
title="En sevdiğiniz renk hangisi?"
|
|
36
|
+
choices={[
|
|
37
|
+
{ id: 1, text: 'Kırmızı' },
|
|
38
|
+
{ id: 2, text: 'Mavi' },
|
|
39
|
+
{ id: 3, text: 'Yeşil' },
|
|
40
|
+
{ id: 4, text: 'Sarı' },
|
|
41
|
+
]}
|
|
42
|
+
onSubmit={handleSubmit}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Gelişmiş Kullanım
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { SimpleQuestion } from 'simple-question-react';
|
|
52
|
+
import type { Choice } from 'simple-question-react';
|
|
53
|
+
import 'simple-question-react/styles.css';
|
|
54
|
+
|
|
55
|
+
function Survey() {
|
|
56
|
+
const handleSubmit = (choice: Choice) => {
|
|
57
|
+
console.log('ID:', choice.id);
|
|
58
|
+
console.log('Text:', choice.text);
|
|
59
|
+
console.log('Data:', choice.data);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<SimpleQuestion
|
|
64
|
+
title="Bu ürünü arkadaşlarınıza tavsiye eder misiniz?"
|
|
65
|
+
choices={[
|
|
66
|
+
{ id: 'yes', text: 'Evet, kesinlikle', data: { score: 10 } },
|
|
67
|
+
{ id: 'maybe', text: 'Belki', data: { score: 5 } },
|
|
68
|
+
{ id: 'no', text: 'Hayır', data: { score: 0 } },
|
|
69
|
+
]}
|
|
70
|
+
onSubmit={handleSubmit}
|
|
71
|
+
submitText="Devam Et"
|
|
72
|
+
defaultSelectedId="maybe"
|
|
73
|
+
className="my-custom-class"
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### SimpleQuestion Props
|
|
82
|
+
|
|
83
|
+
| Prop | Tip | Zorunlu | Default | Açıklama |
|
|
84
|
+
|------|-----|---------|---------|----------|
|
|
85
|
+
| `title` | `string` | ✅ | - | Soru başlığı |
|
|
86
|
+
| `choices` | `Choice[]` | ✅ | - | Seçenekler listesi |
|
|
87
|
+
| `onSubmit` | `(choice: Choice) => void` | ❌ | - | Seçim gönderildiğinde çağrılır |
|
|
88
|
+
| `submitText` | `string` | ❌ | `"Gönder"` | Gönder butonu metni |
|
|
89
|
+
| `defaultSelectedId` | `string \| number` | ❌ | - | Başlangıçta seçili seçenek ID'si |
|
|
90
|
+
| `disabled` | `boolean` | ❌ | `false` | Component'i devre dışı bırakır |
|
|
91
|
+
| `className` | `string` | ❌ | - | Ek CSS class'ı |
|
|
92
|
+
|
|
93
|
+
### Choice Type
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
interface Choice {
|
|
97
|
+
id: string | number; // Benzersiz tanımlayıcı
|
|
98
|
+
text: string; // Görüntülenecek metin
|
|
99
|
+
data?: Record<string, unknown>; // Opsiyonel ek veri
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Özelleştirme
|
|
104
|
+
|
|
105
|
+
### CSS Custom Properties
|
|
106
|
+
|
|
107
|
+
Component'i CSS değişkenleriyle özelleştirebilirsiniz:
|
|
108
|
+
|
|
109
|
+
```css
|
|
110
|
+
.simple-question {
|
|
111
|
+
/* Renkler */
|
|
112
|
+
--sq-primary-color: #3b82f6; /* Ana renk (mavi) */
|
|
113
|
+
--sq-primary-hover: #2563eb;
|
|
114
|
+
--sq-text-color: #1f2937;
|
|
115
|
+
--sq-background: #ffffff;
|
|
116
|
+
|
|
117
|
+
/* Boyutlar */
|
|
118
|
+
--sq-max-width: 600px;
|
|
119
|
+
--sq-padding: 32px;
|
|
120
|
+
--sq-border-radius: 16px;
|
|
121
|
+
|
|
122
|
+
/* Tipografi */
|
|
123
|
+
--sq-font-family: 'Inter', sans-serif;
|
|
124
|
+
--sq-title-size: 20px;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Tüm CSS Değişkenleri
|
|
129
|
+
|
|
130
|
+
| Değişken | Default | Açıklama |
|
|
131
|
+
|----------|---------|----------|
|
|
132
|
+
| `--sq-primary-color` | `#10b981` | Ana tema rengi |
|
|
133
|
+
| `--sq-primary-hover` | `#059669` | Hover durumu rengi |
|
|
134
|
+
| `--sq-text-color` | `#111827` | Başlık metin rengi |
|
|
135
|
+
| `--sq-text-secondary` | `#374151` | İkincil metin rengi |
|
|
136
|
+
| `--sq-border-color` | `#e5e7eb` | Border rengi |
|
|
137
|
+
| `--sq-background` | `#ffffff` | Arka plan rengi |
|
|
138
|
+
| `--sq-max-width` | `500px` | Maksimum genişlik |
|
|
139
|
+
| `--sq-padding` | `24px` | İç boşluk |
|
|
140
|
+
| `--sq-border-radius` | `12px` | Köşe yuvarlaklığı |
|
|
141
|
+
| `--sq-font-family` | `system-ui` | Font ailesi |
|
|
142
|
+
|
|
143
|
+
## TypeScript
|
|
144
|
+
|
|
145
|
+
Paket full TypeScript desteği sunar:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { SimpleQuestion } from 'simple-question-react';
|
|
149
|
+
import type { SimpleQuestionProps, Choice } from 'simple-question-react';
|
|
150
|
+
|
|
151
|
+
// Type-safe props
|
|
152
|
+
const props: SimpleQuestionProps = {
|
|
153
|
+
title: 'Soru',
|
|
154
|
+
choices: [{ id: 1, text: 'Seçenek' }],
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Type-safe callback
|
|
158
|
+
const handleSubmit = (choice: Choice) => {
|
|
159
|
+
// choice.id, choice.text, choice.data hepsi typed
|
|
160
|
+
};
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Browser Desteği
|
|
164
|
+
|
|
165
|
+
- Chrome (son 2 versiyon)
|
|
166
|
+
- Firefox (son 2 versiyon)
|
|
167
|
+
- Safari (son 2 versiyon)
|
|
168
|
+
- Edge (son 2 versiyon)
|
|
169
|
+
|
|
170
|
+
## Lisans
|
|
171
|
+
|
|
172
|
+
MIT © Berat Karatas
|
|
173
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Basit soru component'i - tek seçimli anket sorusu
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <SimpleQuestion
|
|
14
|
+
* title="En sevdiğiniz renk?"
|
|
15
|
+
* choices={[
|
|
16
|
+
* { id: 1, text: 'Kırmızı' },
|
|
17
|
+
* { id: 2, text: 'Mavi' },
|
|
18
|
+
* ]}
|
|
19
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
20
|
+
* />
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function SimpleQuestion({
|
|
24
|
+
title,
|
|
25
|
+
choices,
|
|
26
|
+
onSubmit,
|
|
27
|
+
submitText = 'Gönder',
|
|
28
|
+
defaultSelectedId,
|
|
29
|
+
disabled = false,
|
|
30
|
+
className = ''
|
|
31
|
+
}) {
|
|
32
|
+
var _a;
|
|
33
|
+
// Başlangıç seçimini bul
|
|
34
|
+
const initialChoice = defaultSelectedId ? (_a = choices.find(c => c.id === defaultSelectedId)) !== null && _a !== void 0 ? _a : null : null;
|
|
35
|
+
const [selectedChoice, setSelectedChoice] = react.useState(initialChoice);
|
|
36
|
+
// Seçim değişikliği handler'ı
|
|
37
|
+
const handleSelect = react.useCallback(choice => {
|
|
38
|
+
if (!disabled) {
|
|
39
|
+
setSelectedChoice(choice);
|
|
40
|
+
}
|
|
41
|
+
}, [disabled]);
|
|
42
|
+
// Form gönderimi handler'ı
|
|
43
|
+
const handleSubmit = react.useCallback(() => {
|
|
44
|
+
if (selectedChoice && onSubmit && !disabled) {
|
|
45
|
+
onSubmit(selectedChoice);
|
|
46
|
+
}
|
|
47
|
+
}, [selectedChoice, onSubmit, disabled]);
|
|
48
|
+
// Keyboard accessibility için Enter tuşu desteği
|
|
49
|
+
const handleKeyDown = react.useCallback((event, choice) => {
|
|
50
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
handleSelect(choice);
|
|
53
|
+
}
|
|
54
|
+
}, [handleSelect]);
|
|
55
|
+
return jsxRuntime.jsxs("div", {
|
|
56
|
+
className: `simple-question ${disabled ? 'simple-question--disabled' : ''} ${className}`.trim(),
|
|
57
|
+
role: "group",
|
|
58
|
+
"aria-labelledby": "simple-question-title",
|
|
59
|
+
children: [jsxRuntime.jsx("h3", {
|
|
60
|
+
id: "simple-question-title",
|
|
61
|
+
className: "simple-question__title",
|
|
62
|
+
children: title
|
|
63
|
+
}), jsxRuntime.jsx("div", {
|
|
64
|
+
className: "simple-question__choices",
|
|
65
|
+
role: "radiogroup",
|
|
66
|
+
children: choices.map(choice => {
|
|
67
|
+
const isSelected = (selectedChoice === null || selectedChoice === void 0 ? void 0 : selectedChoice.id) === choice.id;
|
|
68
|
+
return jsxRuntime.jsx("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
role: "radio",
|
|
71
|
+
"aria-checked": isSelected,
|
|
72
|
+
className: `simple-question__choice ${isSelected ? 'simple-question__choice--selected' : ''}`,
|
|
73
|
+
onClick: () => handleSelect(choice),
|
|
74
|
+
onKeyDown: e => handleKeyDown(e, choice),
|
|
75
|
+
disabled: disabled,
|
|
76
|
+
children: choice.text
|
|
77
|
+
}, choice.id);
|
|
78
|
+
})
|
|
79
|
+
}), jsxRuntime.jsx("button", {
|
|
80
|
+
type: "button",
|
|
81
|
+
className: "simple-question__submit",
|
|
82
|
+
onClick: handleSubmit,
|
|
83
|
+
disabled: disabled || !selectedChoice,
|
|
84
|
+
"aria-disabled": disabled || !selectedChoice,
|
|
85
|
+
children: submitText
|
|
86
|
+
})]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* simple-question-react
|
|
92
|
+
*
|
|
93
|
+
* Basit questionnaire component kütüphanesi
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* import { SimpleQuestion } from 'simple-question-react';
|
|
98
|
+
* import 'simple-question-react/styles.css';
|
|
99
|
+
*
|
|
100
|
+
* function App() {
|
|
101
|
+
* return (
|
|
102
|
+
* <SimpleQuestion
|
|
103
|
+
* title="Favori renginiz?"
|
|
104
|
+
* choices={[
|
|
105
|
+
* { id: 1, text: 'Kırmızı' },
|
|
106
|
+
* { id: 2, text: 'Mavi' },
|
|
107
|
+
* ]}
|
|
108
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
109
|
+
* />
|
|
110
|
+
* );
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
// =============================================================================
|
|
115
|
+
// Component Exports
|
|
116
|
+
// =============================================================================
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// Version
|
|
119
|
+
// =============================================================================
|
|
120
|
+
const VERSION = '1.0.0';
|
|
121
|
+
|
|
122
|
+
exports.SimpleQuestion = SimpleQuestion;
|
|
123
|
+
exports.VERSION = VERSION;
|
|
124
|
+
exports.default = SimpleQuestion;
|
|
125
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/components/SimpleQuestion/index.tsx","../src/index.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport type { SimpleQuestionProps, Choice } from './SimpleQuestion.types';\nimport './SimpleQuestion.css';\n\n/**\n * Basit soru component'i - tek seçimli anket sorusu\n *\n * @example\n * ```tsx\n * <SimpleQuestion\n * title=\"En sevdiğiniz renk?\"\n * choices={[\n * { id: 1, text: 'Kırmızı' },\n * { id: 2, text: 'Mavi' },\n * ]}\n * onSubmit={(choice) => console.log(choice)}\n * />\n * ```\n */\nexport function SimpleQuestion({\n title,\n choices,\n onSubmit,\n submitText = 'Gönder',\n defaultSelectedId,\n disabled = false,\n className = '',\n}: SimpleQuestionProps) {\n // Başlangıç seçimini bul\n const initialChoice = defaultSelectedId\n ? choices.find((c) => c.id === defaultSelectedId) ?? null\n : null;\n\n const [selectedChoice, setSelectedChoice] = useState<Choice | null>(initialChoice);\n\n // Seçim değişikliği handler'ı\n const handleSelect = useCallback(\n (choice: Choice) => {\n if (!disabled) {\n setSelectedChoice(choice);\n }\n },\n [disabled]\n );\n\n // Form gönderimi handler'ı\n const handleSubmit = useCallback(() => {\n if (selectedChoice && onSubmit && !disabled) {\n onSubmit(selectedChoice);\n }\n }, [selectedChoice, onSubmit, disabled]);\n\n // Keyboard accessibility için Enter tuşu desteği\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent, choice: Choice) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n handleSelect(choice);\n }\n },\n [handleSelect]\n );\n\n return (\n <div\n className={`simple-question ${disabled ? 'simple-question--disabled' : ''} ${className}`.trim()}\n role=\"group\"\n aria-labelledby=\"simple-question-title\"\n >\n <h3 id=\"simple-question-title\" className=\"simple-question__title\">\n {title}\n </h3>\n\n <div className=\"simple-question__choices\" role=\"radiogroup\">\n {choices.map((choice) => {\n const isSelected = selectedChoice?.id === choice.id;\n\n return (\n <button\n key={choice.id}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n className={`simple-question__choice ${\n isSelected ? 'simple-question__choice--selected' : ''\n }`}\n onClick={() => handleSelect(choice)}\n onKeyDown={(e) => handleKeyDown(e, choice)}\n disabled={disabled}\n >\n {choice.text}\n </button>\n );\n })}\n </div>\n\n <button\n type=\"button\"\n className=\"simple-question__submit\"\n onClick={handleSubmit}\n disabled={disabled || !selectedChoice}\n aria-disabled={disabled || !selectedChoice}\n >\n {submitText}\n </button>\n </div>\n );\n}\n\n// Default export da sağla (esneklik için)\nexport default SimpleQuestion;\n\n// Type'ları da export et (kullanıcılar için)\nexport type { SimpleQuestionProps, Choice } from './SimpleQuestion.types';\n\n","/**\n * simple-question-react\n *\n * Basit questionnaire component kütüphanesi\n *\n * @example\n * ```tsx\n * import { SimpleQuestion } from 'simple-question-react';\n * import 'simple-question-react/styles.css';\n *\n * function App() {\n * return (\n * <SimpleQuestion\n * title=\"Favori renginiz?\"\n * choices={[\n * { id: 1, text: 'Kırmızı' },\n * { id: 2, text: 'Mavi' },\n * ]}\n * onSubmit={(choice) => console.log(choice)}\n * />\n * );\n * }\n * ```\n */\n\n// =============================================================================\n// Component Exports\n// =============================================================================\nexport { SimpleQuestion } from './components';\n\n// Default export (alternatif kullanım için)\nexport { SimpleQuestionDefault as default } from './components';\n\n// =============================================================================\n// Type Exports\n// =============================================================================\nexport type { SimpleQuestionProps, Choice } from './components';\n\n// =============================================================================\n// Version\n// =============================================================================\nexport const VERSION = '1.0.0';\n"],"names":["SimpleQuestion","title","choices","onSubmit","submitText","defaultSelectedId","disabled","className","initialChoice","_a","find","c","id","selectedChoice","setSelectedChoice","useState","handleSelect","useCallback","choice","handleSubmit","handleKeyDown","event","key","preventDefault","_jsxs","trim","role","children","_jsx","map","isSelected","type","onClick","onKeyDown","e","text","VERSION"],"mappings":"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"}
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.simple-question{--sq-primary-color:#10b981;--sq-primary-hover:#059669;--sq-text-color:#111827;--sq-text-secondary:#374151;--sq-border-color:#e5e7eb;--sq-border-hover:#9ca3af;--sq-background:#fff;--sq-background-hover:#f9fafb;--sq-selected-bg:#ecfdf5;--sq-selected-text:#065f46;--sq-disabled-bg:#d1d5db;--sq-disabled-text:#9ca3af;--sq-max-width:500px;--sq-padding:24px;--sq-border-radius:12px;--sq-choice-radius:8px;--sq-gap:8px;--sq-font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;--sq-title-size:18px;--sq-text-size:14px;--sq-transition:all 0.2s cubic-bezier(0.4,0,0.2,1);background:var(--sq-background);border:1px solid var(--sq-border-color);border-radius:var(--sq-border-radius);box-shadow:0 1px 3px rgba(0,0,0,.1),0 1px 2px rgba(0,0,0,.06);font-family:var(--sq-font-family);max-width:var(--sq-max-width);padding:var(--sq-padding)}.simple-question--disabled{opacity:.6;pointer-events:none}.simple-question__title{color:var(--sq-text-color);font-size:var(--sq-title-size);font-weight:600;line-height:1.4;margin:0 0 16px}.simple-question__choices{display:flex;flex-direction:column;gap:var(--sq-gap);margin-bottom:16px}.simple-question__choice{background:var(--sq-background);border:2px solid var(--sq-border-color);border-radius:var(--sq-choice-radius);color:var(--sq-text-secondary);cursor:pointer;font-family:inherit;font-size:var(--sq-text-size);outline:none;padding:12px 16px;position:relative;text-align:left;transition:var(--sq-transition)}.simple-question__choice:hover:not(:disabled){background:var(--sq-background-hover);border-color:var(--sq-border-hover)}.simple-question__choice:focus-visible{border-color:var(--sq-primary-color);box-shadow:0 0 0 3px rgba(16,185,129,.2)}.simple-question__choice--selected{background:var(--sq-selected-bg);border-color:var(--sq-primary-color);color:var(--sq-selected-text)}.simple-question__choice--selected:hover:not(:disabled){background:var(--sq-selected-bg);border-color:var(--sq-primary-hover)}.simple-question__choice--selected:after{color:var(--sq-primary-color);content:"✓";font-size:16px;font-weight:700;position:absolute;right:16px;top:50%;transform:translateY(-50%)}.simple-question__choice:disabled{cursor:not-allowed;opacity:.5}.simple-question__submit{background:var(--sq-primary-color);border:none;border-radius:var(--sq-choice-radius);color:#fff;cursor:pointer;font-family:inherit;font-size:var(--sq-text-size);font-weight:600;outline:none;padding:12px 24px;transition:var(--sq-transition);width:100%}.simple-question__submit:hover:not(:disabled){background:var(--sq-primary-hover);box-shadow:0 4px 6px rgba(0,0,0,.1);transform:translateY(-1px)}.simple-question__submit:focus-visible{box-shadow:0 0 0 3px rgba(16,185,129,.4)}.simple-question__submit:active:not(:disabled){box-shadow:none;transform:translateY(0)}.simple-question__submit:disabled{background:var(--sq-disabled-bg);box-shadow:none;color:var(--sq-disabled-text);cursor:not-allowed;transform:none}@media (prefers-color-scheme:dark){.simple-question{--sq-text-color:#f9fafb;--sq-text-secondary:#d1d5db;--sq-border-color:#374151;--sq-border-hover:#6b7280;--sq-background:#1f2937;--sq-background-hover:#374151;--sq-selected-bg:#064e3b;--sq-selected-text:#6ee7b7}}@media (prefers-reduced-motion:reduce){.simple-question,.simple-question__choice,.simple-question__submit{transition:none}.simple-question__submit:hover:not(:disabled){transform:none}}
|
|
2
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SimpleQuestion.css"],"names":[],"mappings":"AASA,iBAEE,0BAA2B,CAC3B,0BAA2B,CAC3B,uBAAwB,CACxB,2BAA4B,CAC5B,yBAA0B,CAC1B,yBAA0B,CAC1B,oBAAwB,CACxB,6BAA8B,CAC9B,wBAAyB,CACzB,0BAA2B,CAC3B,wBAAyB,CACzB,0BAA2B,CAG3B,oBAAqB,CACrB,iBAAkB,CAClB,uBAAwB,CACxB,sBAAuB,CACvB,YAAa,CAGb,qGACqC,CACrC,oBAAqB,CACrB,mBAAoB,CAGpB,kDAAsD,CAYtD,+BAAgC,CAFhC,uCAAwC,CACxC,qCAAsC,CAEtC,6DAE+B,CAR/B,iCAAkC,CAClC,6BAA8B,CAC9B,yBARF,CAkBA,2BACE,UAAY,CACZ,mBACF,CAKA,wBAIE,0BAA2B,CAF3B,8BAA+B,CAC/B,eAAgB,CAEhB,eAAgB,CAJhB,eAKF,CAKA,0BACE,YAAa,CACb,qBAAsB,CACtB,iBAAkB,CAClB,kBACF,CAKA,yBAKE,+BAAgC,CAFhC,uCAAwC,CACxC,qCAAsC,CAItC,8BAA+B,CAE/B,cAAe,CAJf,mBAAoB,CACpB,6BAA8B,CAK9B,YAAa,CAVb,iBAAkB,CADlB,iBAAkB,CAQlB,eAAgB,CAEhB,+BAEF,CAGA,8CAEE,qCAAsC,CADtC,mCAEF,CAGA,uCACE,oCAAqC,CACrC,wCACF,CAGA,mCAEE,gCAAiC,CADjC,oCAAqC,CAErC,6BACF,CAEA,wDAEE,gCAAiC,CADjC,oCAEF,CAGA,yCAQE,6BAA8B,CAP9B,WAAY,CAKZ,cAAe,CACf,eAAiB,CALjB,iBAAkB,CAClB,UAAW,CACX,OAAQ,CACR,0BAIF,CAGA,kCACE,kBAAmB,CACnB,UACF,CAKA,yBAKE,kCAAmC,CAFnC,WAAY,CACZ,qCAAsC,CAKtC,UAAc,CACd,cAAe,CAJf,mBAAoB,CACpB,6BAA8B,CAC9B,eAAgB,CAIhB,YAAa,CAVb,iBAAkB,CASlB,+BAAgC,CAVhC,UAYF,CAGA,8CACE,kCAAmC,CAEnC,mCAAwC,CADxC,0BAEF,CAGA,uCACE,wCACF,CAGA,+CAEE,eAAgB,CADhB,uBAEF,CAGA,kCACE,gCAAiC,CAIjC,eAAgB,CAHhB,6BAA8B,CAC9B,kBAAmB,CACnB,cAEF,CAKA,mCACE,iBACE,uBAAwB,CACxB,2BAA4B,CAC5B,yBAA0B,CAC1B,yBAA0B,CAC1B,uBAAwB,CACxB,6BAA8B,CAC9B,wBAAyB,CACzB,0BACF,CACF,CAKA,uCACE,mEAGE,eACF,CAEA,8CACE,cACF,CACF","file":"index.css","sourcesContent":["/* ==========================================================================\n SimpleQuestion Component Styles\n CSS Custom Properties ile kolayca özelleştirilebilir\n ========================================================================== */\n\n/* --------------------------------------------------------------------------\n CSS Custom Properties (Değişkenler)\n Kullanıcılar bu değişkenleri override ederek stili özelleştirebilir\n -------------------------------------------------------------------------- */\n.simple-question {\n /* Renkler */\n --sq-primary-color: #10b981;\n --sq-primary-hover: #059669;\n --sq-text-color: #111827;\n --sq-text-secondary: #374151;\n --sq-border-color: #e5e7eb;\n --sq-border-hover: #9ca3af;\n --sq-background: #ffffff;\n --sq-background-hover: #f9fafb;\n --sq-selected-bg: #ecfdf5;\n --sq-selected-text: #065f46;\n --sq-disabled-bg: #d1d5db;\n --sq-disabled-text: #9ca3af;\n\n /* Boyutlar */\n --sq-max-width: 500px;\n --sq-padding: 24px;\n --sq-border-radius: 12px;\n --sq-choice-radius: 8px;\n --sq-gap: 8px;\n\n /* Tipografi */\n --sq-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,\n 'Helvetica Neue', Arial, sans-serif;\n --sq-title-size: 18px;\n --sq-text-size: 14px;\n\n /* Geçişler */\n --sq-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n/* --------------------------------------------------------------------------\n Ana Container\n -------------------------------------------------------------------------- */\n.simple-question {\n font-family: var(--sq-font-family);\n max-width: var(--sq-max-width);\n padding: var(--sq-padding);\n border: 1px solid var(--sq-border-color);\n border-radius: var(--sq-border-radius);\n background: var(--sq-background);\n box-shadow:\n 0 1px 3px rgba(0, 0, 0, 0.1),\n 0 1px 2px rgba(0, 0, 0, 0.06);\n}\n\n/* Disabled state */\n.simple-question--disabled {\n opacity: 0.6;\n pointer-events: none;\n}\n\n/* --------------------------------------------------------------------------\n Başlık\n -------------------------------------------------------------------------- */\n.simple-question__title {\n margin: 0 0 16px 0;\n font-size: var(--sq-title-size);\n font-weight: 600;\n color: var(--sq-text-color);\n line-height: 1.4;\n}\n\n/* --------------------------------------------------------------------------\n Seçenekler Container\n -------------------------------------------------------------------------- */\n.simple-question__choices {\n display: flex;\n flex-direction: column;\n gap: var(--sq-gap);\n margin-bottom: 16px;\n}\n\n/* --------------------------------------------------------------------------\n Seçenek Butonları\n -------------------------------------------------------------------------- */\n.simple-question__choice {\n position: relative;\n padding: 12px 16px;\n border: 2px solid var(--sq-border-color);\n border-radius: var(--sq-choice-radius);\n background: var(--sq-background);\n font-family: inherit;\n font-size: var(--sq-text-size);\n color: var(--sq-text-secondary);\n text-align: left;\n cursor: pointer;\n transition: var(--sq-transition);\n outline: none;\n}\n\n/* Hover state */\n.simple-question__choice:hover:not(:disabled) {\n border-color: var(--sq-border-hover);\n background: var(--sq-background-hover);\n}\n\n/* Focus state (accessibility) */\n.simple-question__choice:focus-visible {\n border-color: var(--sq-primary-color);\n box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);\n}\n\n/* Selected state */\n.simple-question__choice--selected {\n border-color: var(--sq-primary-color);\n background: var(--sq-selected-bg);\n color: var(--sq-selected-text);\n}\n\n.simple-question__choice--selected:hover:not(:disabled) {\n border-color: var(--sq-primary-hover);\n background: var(--sq-selected-bg);\n}\n\n/* Checkmark indicator for selected */\n.simple-question__choice--selected::after {\n content: '✓';\n position: absolute;\n right: 16px;\n top: 50%;\n transform: translateY(-50%);\n font-size: 16px;\n font-weight: bold;\n color: var(--sq-primary-color);\n}\n\n/* Disabled state */\n.simple-question__choice:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n\n/* --------------------------------------------------------------------------\n Gönder Butonu\n -------------------------------------------------------------------------- */\n.simple-question__submit {\n width: 100%;\n padding: 12px 24px;\n border: none;\n border-radius: var(--sq-choice-radius);\n background: var(--sq-primary-color);\n font-family: inherit;\n font-size: var(--sq-text-size);\n font-weight: 600;\n color: #ffffff;\n cursor: pointer;\n transition: var(--sq-transition);\n outline: none;\n}\n\n/* Hover state */\n.simple-question__submit:hover:not(:disabled) {\n background: var(--sq-primary-hover);\n transform: translateY(-1px);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n}\n\n/* Focus state */\n.simple-question__submit:focus-visible {\n box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.4);\n}\n\n/* Active state */\n.simple-question__submit:active:not(:disabled) {\n transform: translateY(0);\n box-shadow: none;\n}\n\n/* Disabled state */\n.simple-question__submit:disabled {\n background: var(--sq-disabled-bg);\n color: var(--sq-disabled-text);\n cursor: not-allowed;\n transform: none;\n box-shadow: none;\n}\n\n/* --------------------------------------------------------------------------\n Dark Mode Support (prefers-color-scheme)\n -------------------------------------------------------------------------- */\n@media (prefers-color-scheme: dark) {\n .simple-question {\n --sq-text-color: #f9fafb;\n --sq-text-secondary: #d1d5db;\n --sq-border-color: #374151;\n --sq-border-hover: #6b7280;\n --sq-background: #1f2937;\n --sq-background-hover: #374151;\n --sq-selected-bg: #064e3b;\n --sq-selected-text: #6ee7b7;\n }\n}\n\n/* --------------------------------------------------------------------------\n Reduced Motion Support (accessibility)\n -------------------------------------------------------------------------- */\n@media (prefers-reduced-motion: reduce) {\n .simple-question,\n .simple-question__choice,\n .simple-question__submit {\n transition: none;\n }\n\n .simple-question__submit:hover:not(:disabled) {\n transform: none;\n }\n}\n\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Seçenek (choice) tipi
|
|
5
|
+
*/
|
|
6
|
+
interface Choice {
|
|
7
|
+
/** Benzersiz tanımlayıcı */
|
|
8
|
+
id: string | number;
|
|
9
|
+
/** Görüntülenecek metin */
|
|
10
|
+
text: string;
|
|
11
|
+
/** Opsiyonel: ek veri */
|
|
12
|
+
data?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* SimpleQuestion component props
|
|
16
|
+
*/
|
|
17
|
+
interface SimpleQuestionProps {
|
|
18
|
+
/** Soru başlığı */
|
|
19
|
+
title: string;
|
|
20
|
+
/** Seçenekler listesi */
|
|
21
|
+
choices: Choice[];
|
|
22
|
+
/** Seçim yapılıp gönderildiğinde çağrılır */
|
|
23
|
+
onSubmit?: (choice: Choice) => void;
|
|
24
|
+
/** Gönder butonu metni */
|
|
25
|
+
submitText?: string;
|
|
26
|
+
/** Opsiyonel: başlangıçta seçili olan seçenek ID'si */
|
|
27
|
+
defaultSelectedId?: string | number;
|
|
28
|
+
/** Opsiyonel: component'i devre dışı bırak */
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** Opsiyonel: ek CSS class'ı */
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Basit soru component'i - tek seçimli anket sorusu
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* <SimpleQuestion
|
|
40
|
+
* title="En sevdiğiniz renk?"
|
|
41
|
+
* choices={[
|
|
42
|
+
* { id: 1, text: 'Kırmızı' },
|
|
43
|
+
* { id: 2, text: 'Mavi' },
|
|
44
|
+
* ]}
|
|
45
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
46
|
+
* />
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function SimpleQuestion({ title, choices, onSubmit, submitText, defaultSelectedId, disabled, className, }: SimpleQuestionProps): react_jsx_runtime.JSX.Element;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* simple-question-react
|
|
53
|
+
*
|
|
54
|
+
* Basit questionnaire component kütüphanesi
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* import { SimpleQuestion } from 'simple-question-react';
|
|
59
|
+
* import 'simple-question-react/styles.css';
|
|
60
|
+
*
|
|
61
|
+
* function App() {
|
|
62
|
+
* return (
|
|
63
|
+
* <SimpleQuestion
|
|
64
|
+
* title="Favori renginiz?"
|
|
65
|
+
* choices={[
|
|
66
|
+
* { id: 1, text: 'Kırmızı' },
|
|
67
|
+
* { id: 2, text: 'Mavi' },
|
|
68
|
+
* ]}
|
|
69
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
70
|
+
* />
|
|
71
|
+
* );
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
declare const VERSION = "1.0.0";
|
|
77
|
+
|
|
78
|
+
export { SimpleQuestion, VERSION, SimpleQuestion as default };
|
|
79
|
+
export type { Choice, SimpleQuestionProps };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Basit soru component'i - tek seçimli anket sorusu
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <SimpleQuestion
|
|
10
|
+
* title="En sevdiğiniz renk?"
|
|
11
|
+
* choices={[
|
|
12
|
+
* { id: 1, text: 'Kırmızı' },
|
|
13
|
+
* { id: 2, text: 'Mavi' },
|
|
14
|
+
* ]}
|
|
15
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
16
|
+
* />
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function SimpleQuestion({
|
|
20
|
+
title,
|
|
21
|
+
choices,
|
|
22
|
+
onSubmit,
|
|
23
|
+
submitText = 'Gönder',
|
|
24
|
+
defaultSelectedId,
|
|
25
|
+
disabled = false,
|
|
26
|
+
className = ''
|
|
27
|
+
}) {
|
|
28
|
+
var _a;
|
|
29
|
+
// Başlangıç seçimini bul
|
|
30
|
+
const initialChoice = defaultSelectedId ? (_a = choices.find(c => c.id === defaultSelectedId)) !== null && _a !== void 0 ? _a : null : null;
|
|
31
|
+
const [selectedChoice, setSelectedChoice] = useState(initialChoice);
|
|
32
|
+
// Seçim değişikliği handler'ı
|
|
33
|
+
const handleSelect = useCallback(choice => {
|
|
34
|
+
if (!disabled) {
|
|
35
|
+
setSelectedChoice(choice);
|
|
36
|
+
}
|
|
37
|
+
}, [disabled]);
|
|
38
|
+
// Form gönderimi handler'ı
|
|
39
|
+
const handleSubmit = useCallback(() => {
|
|
40
|
+
if (selectedChoice && onSubmit && !disabled) {
|
|
41
|
+
onSubmit(selectedChoice);
|
|
42
|
+
}
|
|
43
|
+
}, [selectedChoice, onSubmit, disabled]);
|
|
44
|
+
// Keyboard accessibility için Enter tuşu desteği
|
|
45
|
+
const handleKeyDown = useCallback((event, choice) => {
|
|
46
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
handleSelect(choice);
|
|
49
|
+
}
|
|
50
|
+
}, [handleSelect]);
|
|
51
|
+
return jsxs("div", {
|
|
52
|
+
className: `simple-question ${disabled ? 'simple-question--disabled' : ''} ${className}`.trim(),
|
|
53
|
+
role: "group",
|
|
54
|
+
"aria-labelledby": "simple-question-title",
|
|
55
|
+
children: [jsx("h3", {
|
|
56
|
+
id: "simple-question-title",
|
|
57
|
+
className: "simple-question__title",
|
|
58
|
+
children: title
|
|
59
|
+
}), jsx("div", {
|
|
60
|
+
className: "simple-question__choices",
|
|
61
|
+
role: "radiogroup",
|
|
62
|
+
children: choices.map(choice => {
|
|
63
|
+
const isSelected = (selectedChoice === null || selectedChoice === void 0 ? void 0 : selectedChoice.id) === choice.id;
|
|
64
|
+
return jsx("button", {
|
|
65
|
+
type: "button",
|
|
66
|
+
role: "radio",
|
|
67
|
+
"aria-checked": isSelected,
|
|
68
|
+
className: `simple-question__choice ${isSelected ? 'simple-question__choice--selected' : ''}`,
|
|
69
|
+
onClick: () => handleSelect(choice),
|
|
70
|
+
onKeyDown: e => handleKeyDown(e, choice),
|
|
71
|
+
disabled: disabled,
|
|
72
|
+
children: choice.text
|
|
73
|
+
}, choice.id);
|
|
74
|
+
})
|
|
75
|
+
}), jsx("button", {
|
|
76
|
+
type: "button",
|
|
77
|
+
className: "simple-question__submit",
|
|
78
|
+
onClick: handleSubmit,
|
|
79
|
+
disabled: disabled || !selectedChoice,
|
|
80
|
+
"aria-disabled": disabled || !selectedChoice,
|
|
81
|
+
children: submitText
|
|
82
|
+
})]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* simple-question-react
|
|
88
|
+
*
|
|
89
|
+
* Basit questionnaire component kütüphanesi
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* import { SimpleQuestion } from 'simple-question-react';
|
|
94
|
+
* import 'simple-question-react/styles.css';
|
|
95
|
+
*
|
|
96
|
+
* function App() {
|
|
97
|
+
* return (
|
|
98
|
+
* <SimpleQuestion
|
|
99
|
+
* title="Favori renginiz?"
|
|
100
|
+
* choices={[
|
|
101
|
+
* { id: 1, text: 'Kırmızı' },
|
|
102
|
+
* { id: 2, text: 'Mavi' },
|
|
103
|
+
* ]}
|
|
104
|
+
* onSubmit={(choice) => console.log(choice)}
|
|
105
|
+
* />
|
|
106
|
+
* );
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
// =============================================================================
|
|
111
|
+
// Component Exports
|
|
112
|
+
// =============================================================================
|
|
113
|
+
// =============================================================================
|
|
114
|
+
// Version
|
|
115
|
+
// =============================================================================
|
|
116
|
+
const VERSION = '1.0.0';
|
|
117
|
+
|
|
118
|
+
export { SimpleQuestion, VERSION, SimpleQuestion as default };
|
|
119
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/components/SimpleQuestion/index.tsx","../src/index.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport type { SimpleQuestionProps, Choice } from './SimpleQuestion.types';\nimport './SimpleQuestion.css';\n\n/**\n * Basit soru component'i - tek seçimli anket sorusu\n *\n * @example\n * ```tsx\n * <SimpleQuestion\n * title=\"En sevdiğiniz renk?\"\n * choices={[\n * { id: 1, text: 'Kırmızı' },\n * { id: 2, text: 'Mavi' },\n * ]}\n * onSubmit={(choice) => console.log(choice)}\n * />\n * ```\n */\nexport function SimpleQuestion({\n title,\n choices,\n onSubmit,\n submitText = 'Gönder',\n defaultSelectedId,\n disabled = false,\n className = '',\n}: SimpleQuestionProps) {\n // Başlangıç seçimini bul\n const initialChoice = defaultSelectedId\n ? choices.find((c) => c.id === defaultSelectedId) ?? null\n : null;\n\n const [selectedChoice, setSelectedChoice] = useState<Choice | null>(initialChoice);\n\n // Seçim değişikliği handler'ı\n const handleSelect = useCallback(\n (choice: Choice) => {\n if (!disabled) {\n setSelectedChoice(choice);\n }\n },\n [disabled]\n );\n\n // Form gönderimi handler'ı\n const handleSubmit = useCallback(() => {\n if (selectedChoice && onSubmit && !disabled) {\n onSubmit(selectedChoice);\n }\n }, [selectedChoice, onSubmit, disabled]);\n\n // Keyboard accessibility için Enter tuşu desteği\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent, choice: Choice) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n handleSelect(choice);\n }\n },\n [handleSelect]\n );\n\n return (\n <div\n className={`simple-question ${disabled ? 'simple-question--disabled' : ''} ${className}`.trim()}\n role=\"group\"\n aria-labelledby=\"simple-question-title\"\n >\n <h3 id=\"simple-question-title\" className=\"simple-question__title\">\n {title}\n </h3>\n\n <div className=\"simple-question__choices\" role=\"radiogroup\">\n {choices.map((choice) => {\n const isSelected = selectedChoice?.id === choice.id;\n\n return (\n <button\n key={choice.id}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n className={`simple-question__choice ${\n isSelected ? 'simple-question__choice--selected' : ''\n }`}\n onClick={() => handleSelect(choice)}\n onKeyDown={(e) => handleKeyDown(e, choice)}\n disabled={disabled}\n >\n {choice.text}\n </button>\n );\n })}\n </div>\n\n <button\n type=\"button\"\n className=\"simple-question__submit\"\n onClick={handleSubmit}\n disabled={disabled || !selectedChoice}\n aria-disabled={disabled || !selectedChoice}\n >\n {submitText}\n </button>\n </div>\n );\n}\n\n// Default export da sağla (esneklik için)\nexport default SimpleQuestion;\n\n// Type'ları da export et (kullanıcılar için)\nexport type { SimpleQuestionProps, Choice } from './SimpleQuestion.types';\n\n","/**\n * simple-question-react\n *\n * Basit questionnaire component kütüphanesi\n *\n * @example\n * ```tsx\n * import { SimpleQuestion } from 'simple-question-react';\n * import 'simple-question-react/styles.css';\n *\n * function App() {\n * return (\n * <SimpleQuestion\n * title=\"Favori renginiz?\"\n * choices={[\n * { id: 1, text: 'Kırmızı' },\n * { id: 2, text: 'Mavi' },\n * ]}\n * onSubmit={(choice) => console.log(choice)}\n * />\n * );\n * }\n * ```\n */\n\n// =============================================================================\n// Component Exports\n// =============================================================================\nexport { SimpleQuestion } from './components';\n\n// Default export (alternatif kullanım için)\nexport { SimpleQuestionDefault as default } from './components';\n\n// =============================================================================\n// Type Exports\n// =============================================================================\nexport type { SimpleQuestionProps, Choice } from './components';\n\n// =============================================================================\n// Version\n// =============================================================================\nexport const VERSION = '1.0.0';\n"],"names":["SimpleQuestion","title","choices","onSubmit","submitText","defaultSelectedId","disabled","className","initialChoice","_a","find","c","id","selectedChoice","setSelectedChoice","useState","handleSelect","useCallback","choice","handleSubmit","handleKeyDown","event","key","preventDefault","_jsxs","trim","role","children","_jsx","map","isSelected","type","onClick","onKeyDown","e","text","VERSION"],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "simple-question-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Basit questionnaire component - test paketi",
|
|
5
|
+
"author": "Berat Karatas",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.cjs.js",
|
|
8
|
+
"module": "dist/index.esm.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.esm.js",
|
|
14
|
+
"require": "./dist/index.cjs.js"
|
|
15
|
+
},
|
|
16
|
+
"./styles.css": "./dist/index.css"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"**/*.css"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rollup -c rollup.config.mjs",
|
|
26
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=17.0.0",
|
|
31
|
+
"react-dom": ">=17.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/core": "^7.23.0",
|
|
35
|
+
"@babel/preset-env": "^7.23.0",
|
|
36
|
+
"@babel/preset-react": "^7.23.0",
|
|
37
|
+
"@babel/preset-typescript": "^7.23.0",
|
|
38
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
39
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"@types/react": "^18.2.0",
|
|
43
|
+
"@types/react-dom": "^18.2.0",
|
|
44
|
+
"rollup": "^4.9.0",
|
|
45
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
46
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
47
|
+
"tslib": "^2.6.0",
|
|
48
|
+
"typescript": "^5.3.0"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/bkaratas/npm-publish-test.git"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"react",
|
|
56
|
+
"questionnaire",
|
|
57
|
+
"survey",
|
|
58
|
+
"component",
|
|
59
|
+
"typescript"
|
|
60
|
+
],
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=16.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|