Core survey framework for rendering surveys for Survey-Kit.
npm install @survey-kit/coreCore survey engine for rendering surveys from JSON/YAML configuration.
The core package provides the essential logic and components for building surveys:
- Survey renderers – SurveyRenderer (form-based) and ChatSurveyRenderer (conversational)
- Layout renderer – LayoutRenderer handles page layout, sidebar, and navigation
- State management – useSurvey hook for survey state, navigation, validation, and progress
- Type definitions – TypeScript types for survey and layout configuration
- Validation – Built-in validation with cross-question support
- Conditional logic – Show/hide questions and pages based on answers
- Navigation – Configurable navigation rules (sequential or free-form)
- Full TypeScript support
- Conditional logic and skip logic (shouldShowQuestion, shouldShowPage, etc.)
- Advanced validation (including cross-question validation)
- Hierarchical survey structure (stages → groups → pages → questions)
- Progress tracking at multiple levels (page, group, stage, overall)
- Answer persistence via localStorage
- Multi-Survey Support – Configure multiple distinct surveys with shared routing
- Section Layouts – Configure headers and footers for individual section pages
- Mobile-first, accessible design
``bash`
npm install @survey-kit/core
`tsx
import { SurveyRenderer, LayoutRenderer } from '@survey-kit/core'
import type { SurveyConfig } from '@survey-kit/core'
const config: SurveyConfig = {
id: 'my-survey',
title: 'My Survey',
stages: [
{
id: 'stage-1',
groups: [
{
id: 'group-1',
pages: [
{
id: 'page-1',
questions: [
{
id: 'q1',
type: 'text',
label: 'What is your name?',
required: true,
},
],
},
],
},
],
},
],
}
function MySurvey() {
return (
surveyConfig={config}
components={components}
>
components={components}
onSubmit={handleSubmit}
/>
)
}
`
`tsx
import { ChatSurveyRenderer } from '@survey-kit/core'
function MyChatSurvey() {
return (
components={chatComponents}
onSubmit={handleSubmit}
typingDelay={{ min: 600, max: 1200 }}
/>
)
}
`
``
Survey
├── Stages (optional navigation sections)
│ ├── Groups (logical groupings)
│ │ ├── Pages (one page = one screen)
│ │ │ └── Questions (individual form fields)
- text – Single-line text inputtextarea
- – Multi-line text inputradio
- – Single select from optionscheckbox
- – Multi-select from optionsselect
- – Dropdown selectionemoji-slider
- – Visual rating scale with emojis
`json`
{
"id": "unique-id",
"type": "text|radio|checkbox|select|emoji-slider",
"label": "Question text",
"description": "Optional helper text",
"placeholder": "Input placeholder",
"options": [{ "value": "x", "label": "X" }],
"required": true,
"requiredToNavigate": true,
"showWhen": { "questionId": "other-q", "equals": "value" }
}
Manages survey state including:
- Answers – { [questionId]: { value, touched, valid } }progress
- Navigation – Current page, stage, group tracking
- Validation – Per-question and page-level validation
- Progress – Completion percentage calculation (, stageProgress, groupProgress, overallProgress)
- Persistence – localStorage for answer recovery
`tsx`
const {
state,
currentPage,
progress,
setAnswer,
nextPage,
prevPage,
submitSurvey,
} = useSurvey({ config, onSubmit })
- SurveyRenderer – Traditional form-based survey renderer
- ChatSurveyRenderer – Chat/messaging-style survey renderer
- LayoutRenderer – Wrapper component for survey layout (header, footer, sidebar)
- shouldShowQuestion – Determine if a question should be displayedshouldShowPage
- – Determine if a page should be displayedshouldShowGroup
- – Determine if a group should be displayedshouldShowStage
- – Determine if a stage should be displayedevaluateCondition
- – Evaluate a single conditionevaluateConditions
- – Evaluate multiple conditions with logic operators
- Built-in validation rules (required, min/max length, pattern matching)
- Cross-question validation support
- Custom validation functions
- normaliseSurveyConfig – Normalise survey configurationgetAllPages
- – Get all pages from a survey configfindPageById
- – Find a page by IDgetPageLocation
- – Get the location of a page (stage, group, page)
- SurveyRenderer – Form-based survey rendererChatSurveyRenderer
- – Chat-based survey rendererLayoutRenderer
- – Layout wrapper component
- useSurvey – Survey state management hook
- SurveyConfig, SurveyPage, SurveyQuestion, SurveyStage, SurveyGroupSurveyState
- , QuestionAnswer, QuestionTypeLayoutConfig
- , SectionConfig, SectionLayoutValidationRule
- , Condition, ConditionalLogic
- Conditional logic: shouldShowQuestion, shouldShowPage, shouldShowGroup, shouldShowStage, evaluateCondition, evaluateConditionsnormaliseSurveyConfig
- Config utilities: , getAllPages, findPageById, getPageLocation
- React 19+
- @survey-kit/registry` (peer dependency)
MIT