$attributes Additional attributes */ function form_section( string $title = '', string $subtitle = '', array $attributes = [], string $customSubtitleClass = '' ): string { $subtitleClass = 'text-sm text-gray-600'; if ($customSubtitleClass !== '') { $subtitleClass = $customSubtitleClass; } $section = '
\n"; $info = '

' . $title . '

' . $subtitle . '

'; return $section . $info . '
'; } } //-------------------------------------------------------------------- if (! function_exists('form_section_close')) { /** * Form Section close Tag */ function form_section_close(string $extra = ''): string { return '
' . $extra; } } //-------------------------------------------------------------------- if (! function_exists('form_switch')) { /** * Form Checkbox Switch * * Abstracts form_label to stylize it as a switch toggle * * @param mixed[] $data * @param mixed[] $extra */ function form_switch( string $label = '', array $data = [], string $value = '', bool $checked = false, string $class = '', array $extra = [] ): string { $data['class'] = 'form-switch'; return ''; } } //-------------------------------------------------------------------- if (! function_exists('form_label')) { /** * Form Label Tag * * @param string $text The text to appear onscreen * @param string $id The id the label applies to * @param array $attributes Additional attributes * @param string $hintText Hint text to add next to the label * @param boolean $isOptional adds an optional text if true */ function form_label( string $text = '', string $id = '', array $attributes = [], string $hintText = '', bool $isOptional = false ): string { $label = ' $val) { $label .= ' ' . $key . '="' . $val . '"'; } } $labelContent = $text; if ($isOptional) { $labelContent .= '(' . lang('Common.optional') . ')'; } if ($hintText !== '') { $labelContent .= hint_tooltip($hintText, 'ml-1'); } return $label . '>' . $labelContent . ''; } } //-------------------------------------------------------------------- if (! function_exists('form_multiselect')) { /** * Multi-select menu * * @param array $options * @param string[] $selected * @param array $customExtra */ function form_multiselect( string $name = '', array $options = [], array $selected = [], array $customExtra = [] ): string { $defaultExtra = [ 'data-class' => $customExtra['class'], 'multiple' => 'multiple', ]; $extra = array_merge($defaultExtra, $customExtra); return form_dropdown($name, $options, $selected, $extra); } } //-------------------------------------------------------------------- if (! function_exists('form_dropdown')) { /** * Drop-down Menu (based on html select tag) * * @param array $options * @param string[] $selected * @param array $customExtra */ function form_dropdown( string $name = '', array $options = [], array $selected = [], array $customExtra = [] ): string { $defaultExtra = [ 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($defaultExtra, $customExtra); $defaults = [ 'name' => $name, ]; // standardize selected as strings, like the option keys will be. foreach ($selected as $key => $item) { $selected[$key] = $item; } $placeholderOption = ''; if (isset($extra['placeholder'])) { $placeholderOption = ''; unset($extra['placeholder']); } $extra = stringify_attributes($extra); $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : ''; $form = '\n"; } } //-------------------------------------------------------------------- if (! function_exists('form_editor')) { /** * Markdown editor * * @param array $data * @param array|string $extra */ function form_markdown_editor(array $data = [], string $value = '', string | array $extra = ''): string { $editorClass = 'w-full flex flex-col bg-white border border-gray-500 focus-within:ring-1 focus-within:ring-blue-600'; if (array_key_exists('class', $data) && $data['class'] !== '') { $editorClass .= ' ' . $data['class']; unset($data['class']); } $data['class'] = 'border-none outline-none focus:border-none focus:outline-none w-full h-full'; return '
' . '
' . '' . '' . '' . '' . '' . '
' . '' . icon( 'heading' ) . '' . '' . icon( 'bold' ) . '' . '' . icon( 'italic' ) . '' . '
' . '
' . '' . icon( 'list-unordered' ) . '' . '' . icon( 'list-ordered' ) . '' . '
' . '
' . '' . icon( 'quote' ) . '' . '' . icon( 'link' ) . '' . '' . icon( 'image-add' ) . '' . '
' . '
' . '
' . '
' . form_textarea($data, $value, $extra) . '' . '
' . '' . '
'; } } // ------------------------------------------------------------------------