django-unfold icon indicating copy to clipboard operation
django-unfold copied to clipboard

feat: Enable overriding widget classes

Open HT-Moh opened this issue 10 months ago • 0 comments

  • Move widget class variables to settings for centralized management.
  • Update widgets to retrieve class attributes using the get_config function.
  • Include new variables in the get_config function to support customization.
  • Clean up imports in admin files and use get_config for widget classes.
  • Using get_config on forms.py and sites.py
  • Using get_config on filters and import_export forms.py

Usage: settings.py

BASE_CLASSES = [
  'border',
  'bg-white',
  'font-medium',
  'rounded-md',
  'shadow-sm',
  'text-gray-500',
  'text-sm',
  'focus:ring',
  'focus:ring-primary-300',
  'focus:border-primary-600',
  'focus:outline-none',
  'group-[.errors]:border-red-600',
  'group-[.errors]:focus:ring-red-200',
  'dark:bg-gray-900',
  'dark:border-gray-700',
  'dark:text-gray-400',
  'dark:focus:border-primary-600',
  'dark:focus:ring-primary-700',
  'dark:focus:ring-opacity-50',
  'dark:group-[.errors]:border-red-500',
  'dark:group-[.errors]:focus:ring-red-600/40',
]

SELECT_CLASSES = [
  *BASE_CLASSES,
  'px-3',
  'py-2',
  'pr-8',
  'flex-grow',
  'max-w-2xl',
  'appearance-none',
  'truncate',
]


UNFOLD = {
  'SITE_TITLE': "Site name",
  'SITE_HEADER': None
  'SELECT_CLASSES': SELECT_CLASSES,
}

You can change classed by adding them to UNFOLD #340

HT-Moh avatar Apr 03 '24 16:04 HT-Moh